Re: Removing Cayenne cache groups

From: Bob Schellink (sabob..mail.com)
Date: Sat May 29 2010 - 04:22:36 UTC

  • Next message: Joe Baldwin: "Re: Removing Cayenne cache groups"

    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



    This archive was generated by hypermail 2.0.0 : Sat May 29 2010 - 04:23:17 UTC