You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Gary Jarrel <ga...@gmail.com> on 2011/09/13 15:30:06 UTC

3.1 Module & Cache Configuration

Hi All Again,

Still doing testing on the new configuration and rewriting some code
to 3.1, and have come across the following issue:

My configuration code again:

Module extensions = new Module() {
    @Override
    public void configure(Binder binder) {
        binder.bind(QueryCache.class).to(OSQueryCache.class);
    }
};

ServerRuntime sr = new ServerRuntime("cayenne-cdao.xml", extensions);
DataDomain domain = sr.getDataDomain();
DataNode node = domain.getNode("cdaoNode");
node.setDataSource(dataSource);

Since I'm testing how my app handles caching invalidation using the
new DataChannelFilter I have 2 utility methods:

protected QueryCache getSharedCache() {
    NestedQueryCache cache = (NestedQueryCache) ((DataContext)
getDataContext()).getParentDataDomain().getQueryCache();
    if (osCache)
        assertEquals(OSQueryCache.class, cache.getDelegate().getClass());

    return cache.getDelegate();
}

protected QueryCache getLocalCache() {
    NestedQueryCache cache = (NestedQueryCache) ((DataContext)
getDataContext()).getQueryCache();
    if (osCache)
        assertEquals(OSQueryCache.class, cache.getDelegate().getClass());

    return cache.getDelegate();
}

In the test case 2 simple calls as follows:

OSQueryCache domainCache = (OSQueryCache) getSharedCache();
OSQueryCache contextCache = (OSQueryCache) getLocalCache();

now what I am finding is that both domainCache and contextCache is the
same object, when I would have though they would have been two
different instance of OSQueryCache given that one is the local cache
and the other is the shared cache.

Is there something I am missing here?

Thank you

garyj

Re: 3.1 Module & Cache Configuration

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Sep 13, 2011, at 5:12 PM, Gary Jarrel wrote:

> I have an annotation similar to
> CacheGroups but it goes further into tracking whether an object should
> be cached in local or shared cache.

Also keep in mind that Cayenne uses QueryCache for caching query results. There is still a separate cache for individual objects (we'll be unifying this at some point, but not yet). So even in our cayenne-lifecycle code we are dealing with "cache groups", not objects, when invalidating stuff in the cache.

Andrus


Re: 3.1 Module & Cache Configuration

Posted by Gary Jarrel <ga...@gmail.com>.
I'm testing a DataChannelFilter very similar to
CacheInvalidationFilter with a few extras mainly invalidating groups
in either Shared or Local caches. I have an annotation similar to
CacheGroups but it goes further into tracking whether an object should
be cached in local or shared cache.

I'll dig around a bit more in the code of NestedQueryCache and see
what I can find.

Thank you

garyj

On Tue, Sep 13, 2011 at 11:59 PM, Andrus Adamchik
<an...@objectstyle.org> wrote:
> Not quite sure what you are planning to test, but my guess would be you need to use NestedQueryCache instance.
>
> Andrus
>
> On Sep 13, 2011, at 4:49 PM, Gary Jarrel wrote:
>
>> Ahhh I see :) so what is the best way to test local and shared cache
>> from the point of view of adding and removing objects?
>>
>> garyj
>>
>> On Tue, Sep 13, 2011 at 11:34 PM, Andrus Adamchik
>> <an...@objectstyle.org> wrote:
>>>
>>> On Sep 13, 2011, at 4:30 PM, Gary Jarrel wrote:
>>>
>>>> now what I am finding is that both domainCache and contextCache is the
>>>> same object, when I would have though they would have been two
>>>> different instance of OSQueryCache given that one is the local cache
>>>> and the other is the shared cache.
>>>
>>> You unwrapped the NestedQueryCache yourself, so yeah, underneath it is the same object ;)
>>>
>>> NestedQueryCache just maps itself to a unique "region" of the same cache object. This way you can manage the size, notifications, expiration, etc. of a single cache, and not N+1 caches where N is the number of ObjectContexts in the system.
>>>
>>> Andrus
>>
>
>

Re: 3.1 Module & Cache Configuration

Posted by Andrus Adamchik <an...@objectstyle.org>.
Not quite sure what you are planning to test, but my guess would be you need to use NestedQueryCache instance.

Andrus

On Sep 13, 2011, at 4:49 PM, Gary Jarrel wrote:

> Ahhh I see :) so what is the best way to test local and shared cache
> from the point of view of adding and removing objects?
> 
> garyj
> 
> On Tue, Sep 13, 2011 at 11:34 PM, Andrus Adamchik
> <an...@objectstyle.org> wrote:
>> 
>> On Sep 13, 2011, at 4:30 PM, Gary Jarrel wrote:
>> 
>>> now what I am finding is that both domainCache and contextCache is the
>>> same object, when I would have though they would have been two
>>> different instance of OSQueryCache given that one is the local cache
>>> and the other is the shared cache.
>> 
>> You unwrapped the NestedQueryCache yourself, so yeah, underneath it is the same object ;)
>> 
>> NestedQueryCache just maps itself to a unique "region" of the same cache object. This way you can manage the size, notifications, expiration, etc. of a single cache, and not N+1 caches where N is the number of ObjectContexts in the system.
>> 
>> Andrus
> 


Re: 3.1 Module & Cache Configuration

Posted by Gary Jarrel <ga...@gmail.com>.
Ahhh I see :) so what is the best way to test local and shared cache
from the point of view of adding and removing objects?

garyj

On Tue, Sep 13, 2011 at 11:34 PM, Andrus Adamchik
<an...@objectstyle.org> wrote:
>
> On Sep 13, 2011, at 4:30 PM, Gary Jarrel wrote:
>
>> now what I am finding is that both domainCache and contextCache is the
>> same object, when I would have though they would have been two
>> different instance of OSQueryCache given that one is the local cache
>> and the other is the shared cache.
>
> You unwrapped the NestedQueryCache yourself, so yeah, underneath it is the same object ;)
>
> NestedQueryCache just maps itself to a unique "region" of the same cache object. This way you can manage the size, notifications, expiration, etc. of a single cache, and not N+1 caches where N is the number of ObjectContexts in the system.
>
> Andrus

Re: 3.1 Module & Cache Configuration

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Sep 13, 2011, at 4:30 PM, Gary Jarrel wrote:

> now what I am finding is that both domainCache and contextCache is the
> same object, when I would have though they would have been two
> different instance of OSQueryCache given that one is the local cache
> and the other is the shared cache.

You unwrapped the NestedQueryCache yourself, so yeah, underneath it is the same object ;)

NestedQueryCache just maps itself to a unique "region" of the same cache object. This way you can manage the size, notifications, expiration, etc. of a single cache, and not N+1 caches where N is the number of ObjectContexts in the system.

Andrus