On Aug 1, 2006, at 2:52 PM, Bryan Lewis wrote:

I have some old code that I've been running for a long time. It creates
a caching SelectQuery like this:

    SelectQuery query = new SelectQuery("MyEntityName");
    query.setCachePolicy(QueryMetadata.SHARED_CACHE);
    query.setName("MyQueryName");
    if (refreshing) {
        query.setRefreshingObjects(true);
    }
    else {
        query.setRefreshingObjects(false);
    }
    List objects = dataContext.performQuery(query);

The change in 1.2 was in better defining the distinction of "cache policy" vs. "refreshingObjects" flag. The former defines whether the query is run at all; the later - whether the individual objects within the result are refreshed IF the query is run. The other way of looking at it is "list caching vs. object caching".

So to force a refetch you may do this:

    query.setName("MyQueryName");
    if (refreshing) {
        query.setCachePolicy(QueryMetadata.SHARED_CACHE_REFRESH);
    }
    else {
        query.setCachePolicy(QueryMetadata.SHARED_CACHE);
    }

Andrus

P.S. as an aside, I already have some code on the HEAD (Cayenne 3.0) that support pluggable cache managers, so the query results can be invalidated based on some declarative policy, instead of doing this in the code.

Reply via email to