If you have access to the ObjectContext with which you originally registered the cache group, (which I personally get via a call to the BaseContext), then that should be your DataContext instance.
On May 29, 2010, at 12:22 AM, Bob Schellink wrote: > Sorry for my late reply. > > On 28/05/2010 00:48, Bryan Lewis wrote: >> This email made me aware of that cool new removeGroup and OSCache features. >> Thanks. Two little howevers... >> >> In my testing, it worked only with LOCAL_CACHE, as the original poster >> said. Not a big deal for me; SHARED_CACHE is rarely necessary. The same >> was true with OSCache. > > > Did some more testing (and reading Gary Jarrel's thread[1]) and it turns out > I've misunderstood > LOCAL vs SHARED caching. I now understand that: > > - LOCAL_CACHE is cached in a QueryCache at the ObjectContext level > - SHARED_CACHE is cached in a QueryCache at the DataDomain level > - These two cached are independent e.g. invoking removeGroups on the > ObjectContext QueryCache won't > clear the DataDomain QueryCache. > > The Java example in the doco > (http://cayenne.apache.org/doc30/query-result-caching.html) shows how > to clear the cache in a post-commit callback, but it targets the > ObjectContext cache, in other > words, LOCAL_CACHE. > > In order to clear a group from the SHARED_CACHE one needs to lookup the > DataDomain's QueryCache and > invoke removeGroup on that cache. The following seems to work: > > void onCommit() { > QueryCache cache = > customer.getDataContext().getParentDataDomain().getQueryCache(); > if(isModern()) { > cache.removeGroup("modern"); > } > else { > cache.removeGroup("classic"); > } > } > > That said, DataObject.getDataContext is deprecated. What is the recommended > way to lookup the > DataDomain from inside a DataObject callback? > Configuration.getSharedConfiguration().getDomain()? > > Kind regards > > Bob > > [1]: http://markmail.org/message/5qgrpbs2hjz7qxbx