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;
}
Aggregations