On 18 January 2014 19:12, GESCONSULTOR <[email protected]> wrote:

> Thanks, Dan.
>
> How this complements the DataNucleus L2 cache?
>

The L2 cache s a cache of domain objects that are held in memory between
requests.  This is exploited primarily when walking the graph of domain
objects on subsequent requests.

The QueryResultsCache, on the other hand, is request scoped and so its
contents is thrown away after each request.  What it caches is different
also, namely the set of objects that are returned from running a single
query.




> Should we explicitly use the cache in our repositories?
>

Only if by profiling you realise that they are a being called many times,
and that you know that the result is idempotent (at least within a request
scope).




>  I can wait to see how it' used on Estatio if it's easier to see than
> explain
>
>
There's an example in [2].  Currently that code is using a class called
EstatioInteractionCache, but it's basically the same as QueryResultsCache.
 Anyway, we discovered that this method can be called many times (when we
calculate the invoices for all leases in the system).  So this allows the
results of that query to be cached for all subsequent calls.

The benefit of this is that the domain object code can still be written
"naively", (so is still expressive), but we can boost the performance (by
avoiding network calls) where necessary.


~~~
It occurs to me that - rather than require the dev to open up the
repository method implementation and explicitly use QueryResultsCache -- we
could (perhaps) introduce a new annotation such that this is done in a
declarative fashion, eg:

    @QueryResultsCacheable // ? a new annotation ?
    @ActionSemantics(Of.SAFE)
    @Programmatic
    public IndexValue findIndexValueByIndexAndStartDate(
        ...
    )

That would require the repository being wrapped in a proxy, but I'm already
doing that for these new request-scoped services.

Speak up if you'd like that ability....

Cheers
Dan


[1] http://www.datanucleus.org/products/accessplatform/jdo/cache.html
[2]
https://github.com/estatio/estatio/blob/ba94ed50f6c516d4028c4f827beb46cdc6124f06/dom/src/main/java/org/estatio/dom/index/IndexValues.java#L88

Reply via email to