cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Further on Cache Groups
Date Tue, 01 Jun 2010 15:17:54 GMT
Exactly. Sorry I forgot to mention this distinction. BTW, as a result  
OSCache is much more efficient, as group expiration is done without  
scanning through all entries. MapQueryCacheFactory probably won't work  
for large caches with tens of thousands of entries or more.

As for the naming, I guess we can call it "expire" instead of remove  
going forward (or at least write better javadocs). It is confusing  
indeed.

Andrus


On May 31, 2010, at 9:44 AM, Bryan Lewis wrote:

> 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
View raw message