use of com.alicp.jetcache.CacheGetResult in project jetcache by alibaba.
the class DefaultCacheMonitor method afterGetAll.
private void afterGetAll(long millis, Set keys, MultiGetResult result) {
if (keys == null) {
return;
}
int keyCount = keys.size();
cacheStat.minGetTime = Math.min(cacheStat.minGetTime, millis);
cacheStat.maxGetTime = Math.max(cacheStat.maxGetTime, millis);
cacheStat.getTimeSum += millis;
cacheStat.getCount += keyCount;
Map resultValues = result.getValues();
if (resultValues == null) {
cacheStat.getFailCount += keyCount;
} else {
for (Object singleResult : resultValues.values()) {
CacheGetResult r = ((CacheGetResult) singleResult);
parseSingleGet(r);
}
}
}
use of com.alicp.jetcache.CacheGetResult in project jetcache by alibaba.
the class CacheHandler method invokeWithCache.
private static Object invokeWithCache(CacheInvokeContext context) throws Throwable {
Cache cache = context.cacheFunction.apply(context);
if (cache == null) {
logger.error("no cache with name: " + context.method);
return invokeOrigin(context);
}
Object key = context.args;
if (key == null) {
key = "_$JETCACHE_NULL_KEY$_";
}
if (!ExpressionUtil.evalCondition(context)) {
return loadAndCount(context, cache, key);
}
// the semantics of "unless" and "cacheNullValue" is not very accurate, we do our best to process it.
CacheGetResult cacheGetResult = cache.GET(key);
if (cacheGetResult.isSuccess()) {
context.result = cacheGetResult.getValue();
}
if (!cacheGetResult.isSuccess()) {
//not hit
context.result = loadAndCount(context, cache, key);
if (!canNotCache(context)) {
cache.put(key, context.result);
}
} else {
//cache hit
if (canNotCache(context)) {
//reload
context.result = loadAndCount(context, cache, key);
if (!canNotCache(context)) {
//eval again
cache.put(key, context.result);
}
}
}
return context.result;
}
Aggregations