Search in sources :

Example 1 with CacheGetResult

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);
        }
    }
}
Also used : CacheGetResult(com.alicp.jetcache.CacheGetResult) Map(java.util.Map)

Example 2 with CacheGetResult

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;
}
Also used : CacheGetResult(com.alicp.jetcache.CacheGetResult) AbstractCache(com.alicp.jetcache.AbstractCache) Cache(com.alicp.jetcache.Cache) ProxyCache(com.alicp.jetcache.ProxyCache)

Aggregations

CacheGetResult (com.alicp.jetcache.CacheGetResult)2 AbstractCache (com.alicp.jetcache.AbstractCache)1 Cache (com.alicp.jetcache.Cache)1 ProxyCache (com.alicp.jetcache.ProxyCache)1 Map (java.util.Map)1