Search in sources :

Example 6 with QueryCache

use of org.apache.cayenne.cache.QueryCache in project cayenne by apache.

the class DataDomainQueryAction method interceptSharedCache.

/*
     * Wraps execution in shared cache checks
     */
private final boolean interceptSharedCache() {
    if (metadata.getCacheKey() == null) {
        return !DONE;
    }
    boolean cache = QueryCacheStrategy.SHARED_CACHE == metadata.getCacheStrategy();
    boolean cacheOrCacheRefresh = cache || QueryCacheStrategy.SHARED_CACHE_REFRESH == metadata.getCacheStrategy();
    if (!cacheOrCacheRefresh) {
        return !DONE;
    }
    QueryCache queryCache = domain.getQueryCache();
    QueryCacheEntryFactory factory = getCacheObjectFactory();
    if (cache) {
        List cachedResults = queryCache.get(metadata, factory);
        // there was a preexisting cache entry
        if (response == null) {
            response = new ListResponse(cachedResults);
        }
        if (cachedResults instanceof ListWithPrefetches) {
            this.prefetchResultsByPath = ((ListWithPrefetches) cachedResults).getPrefetchResultsByPath();
        }
    } else {
        // on cache-refresh request, fetch without blocking and fill the
        // cache
        queryCache.put(metadata, factory.createObject());
    }
    return DONE;
}
Also used : QueryCache(org.apache.cayenne.cache.QueryCache) ListResponse(org.apache.cayenne.util.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) QueryCacheEntryFactory(org.apache.cayenne.cache.QueryCacheEntryFactory)

Aggregations

QueryCache (org.apache.cayenne.cache.QueryCache)6 List (java.util.List)3 QueryCacheEntryFactory (org.apache.cayenne.cache.QueryCacheEntryFactory)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Module (org.apache.cayenne.di.Module)2 Serializable (java.io.Serializable)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ObjectContext (org.apache.cayenne.ObjectContext)1 MapQueryCache (org.apache.cayenne.cache.MapQueryCache)1 MockQueryCache (org.apache.cayenne.cache.MockQueryCache)1 E1 (org.apache.cayenne.cache.invalidation.db.E1)1 E2 (org.apache.cayenne.cache.invalidation.db.E2)1 CayenneRuntime (org.apache.cayenne.configuration.CayenneRuntime)1 DIBootstrap (org.apache.cayenne.di.DIBootstrap)1 Injector (org.apache.cayenne.di.Injector)1 GraphDiff (org.apache.cayenne.graph.GraphDiff)1 ObjectSelect (org.apache.cayenne.query.ObjectSelect)1 QueryMetadata (org.apache.cayenne.query.QueryMetadata)1