cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Jarrel <>
Subject Re: More on caching
Date Fri, 28 May 2010 07:17:08 GMT
On Fri, May 28, 2010 at 4:43 PM, Andrus Adamchik <> wrote:

>> it seems that domain.getQueryCache().size() is returning 1
>> assertEquals(1, ((DataContext)
>> getDataContext()).getParentDataDomain().getQueryCache().size());
>> assertEquals(1, ((DataContext) getDataContext()).getQueryCache().size());
> I guess DataContext is assigned a different QueryCache instance somehow.
> Andrus

I've just traced though the code and it seems that the queryCache
member in DataContext never gets set. Cayenne uses the DataDomain
query cache which is created on the first execution of my select
query. The second select query also uses this cache. The call in the
first assertEquals uses this cache is subsequently returns the correct
result. However in the second assertEquals statement the method on
line 226 of DataContext is executed.

public QueryCache getQueryCache() {
    if (queryCache == null) {
        synchronized (this) {
            if (queryCache == null) {

                DataDomain domain = getParentDataDomain();
                queryCache = domain.getQueryCacheFactory().getQueryCache(

    return queryCache;

At this point queryCache within the DataContext is still null so it
goes of and creates another one hence the cache is empty.

This could however be the correct behavior if the DataDomain holds the
shared cache, while the data context holds the local cache, but if
this is the case perhaps it needs to be documented a bit better?



View raw message