cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Lewis <jbryanle...@gmail.com>
Subject Re: Further on Cache Groups
Date Mon, 31 May 2010 13:44:24 GMT
I debugged through your test case to learn more about caching.  The problem
is that QueryCache's method names are misleading when running with OSCache.

QueryCache.removeGroup() doesn't actually remove anything from the OSCache.
It calls osCache.flushGroup().
Similarly, clear() doesn't empty the cache; it calls flushAll().
cache.size() remains the same after these calls.  (Not the case with
MapQueryCacheFactory.)

If you want to see a change in size() you have to call
osCache.removeEntry(), as you discovered.  (Or Cayenne's wrapper method
remove().)



On Sun, May 30, 2010 at 10:44 PM, Gary Jarrel <garyjarrel@gmail.com> wrote:

> Hi All!
>
> Another interesting thing that I have just come across in relation to
> cache grouping and to continue on Bob's thread "Removing Cayenne cache
> groups" I have the following two test cases.
>
> @SuppressWarnings("unchecked")
> public void testBasicSelectQueryWithoutDaoWithSharedCache() {
>    QueryCache domainCache = getSharedCache();
>    QueryCache contextCache = getLocalCache();
>
>    // this is one in the shared cache
>    assertEquals(0, domainCache.size());
>
>    // this is 0 in the local cache
>    assertEquals(0, contextCache.size());
>
>    SelectQuery q = new SelectQuery(Admin.class);
>    q.setCacheGroups("testGroup");
>    q.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
>
>    List<Admin> result = getDataContext().performQuery(q);
>    assertEquals(2, result.size());
>
>    // this is one in the shared cache
>    assertEquals(1, domainCache.size());
>
>    // this is 0 in the local cache
>    assertEquals(0, contextCache.size());
> }
>
> @SuppressWarnings("unchecked")
> public void testBasicSelectQueryWithoutDaoWithLocalCache() {
>    QueryCache domainCache = getSharedCache();
>    QueryCache contextCache = getLocalCache();
>
>    // this is one in the shared cache
>    assertEquals(0, domainCache.size());
>
>    // this is 0 in the local cache
>    assertEquals(0, contextCache.size());
>
>    SelectQuery q = new SelectQuery(Admin.class);
>    q.setCacheGroups("testGroup");
>    q.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
>
>    List<Admin> result = getDataContext().performQuery(q);
>    assertEquals(2, result.size());
>
>    // this is one in the shared cache
>    assertEquals(0, domainCache.size());
>
>    // this is 0 in the local cache
>    assertEquals(1, contextCache.size());
> }
>
> and the following initialization method that runs before each test case.
>
> private void initCache() {
>    DataContext context = (DataContext) getDataContext();
>    DataDomain domain = context.getParentDataDomain();
>
>    domain.setQueryCacheFactory(new OSQueryCacheFactory());
>    domain.setSharedCacheEnabled(true);
>    this.osCache = true;
>
>    QueryCache localCache = getLocalCache();
>    QueryCache sharedCache = getSharedCache();
>
>    sharedCache.clear();
>    localCache.clear();
>
>    sharedCache.removeGroup("testGroup");
>    localCache.removeGroup("testGroup");
>
>    if (osCache) {
>        OSQueryCache sharedOSCache = (OSQueryCache) sharedCache;
>        sharedOSCache.getOsCache().removeEntry("testGroup");
>        //sharedOSCache.getOsCache().removeEntry("Admin");
>    }
> }
>
> When run one by one the test cases succeed fine. However when run all
> together the second test case fails on the following line at the very
> start:
>
> // this is one in the shared cache
> assertEquals(0, domainCache.size());
>
> This will happen if I keep the last line of the init method commented
> out which is:
>
> sharedOSCache.getOsCache().removeEntry("Admin");
>
> As soon as the line is uncommented then everything runs fine. This is
> despite the fact that I am removing my testGroup before each test
> case.
>
> Any thoughts?
>
> Thank you
>
> Gary
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message