use of javax.cache.annotation.GeneratedCacheKey in project Payara by payara.
the class CachePutInterceptor method doPut.
@SuppressWarnings("unchecked")
private void doPut(PayaraCacheKeyInvocationContext<CachePut> pctx) throws Throwable {
CacheKeyGenerator generator = pctx.getGenerator();
CacheResolverFactory resolverF = pctx.getFactory();
CacheResolver cacheResolver = resolverF.getCacheResolver(pctx);
Cache cache = cacheResolver.resolveCache(pctx);
GeneratedCacheKey key = generator.generateCacheKey(pctx);
Object value = pctx.getValueParameter().getValue();
cache.put(key, value);
}
use of javax.cache.annotation.GeneratedCacheKey in project Payara by payara.
the class CacheResultInterceptor method cacheResult.
@AroundInvoke
@SuppressWarnings("unchecked")
public Object cacheResult(InvocationContext ctx) throws Throwable {
if (!isEnabled()) {
return ctx.proceed();
}
// get my annotation
CacheResult annotation = ctx.getMethod().getAnnotation(CacheResult.class);
PayaraCacheKeyInvocationContext<CacheResult> pctx = new PayaraCacheKeyInvocationContext<>(ctx, annotation);
CacheResolverFactory resolverF = pctx.getFactory();
CacheResolver cacheResolver = resolverF.getCacheResolver(pctx);
Cache cache = cacheResolver.resolveCache(pctx);
boolean cacheExceptions = (annotation.exceptionCacheName() != null && annotation.exceptionCacheName().length() > 0);
CacheKeyGenerator generator = pctx.getGenerator();
GeneratedCacheKey key = generator.generateCacheKey(pctx);
if (!annotation.skipGet()) {
Object cacheResult = cache.get(key);
if (cacheResult != null) {
return cacheResult;
} else {
// check exception cache
if (cacheExceptions) {
Cache exceptionCache = resolverF.getExceptionCacheResolver(pctx).resolveCache(pctx);
Throwable e = (Throwable) exceptionCache.get(key);
if (e != null) {
throw e;
}
}
}
}
// call the method
Object result = null;
try {
result = ctx.proceed();
cache.put(key, result);
} catch (Throwable e) {
if (cacheExceptions) {
Cache exceptionCache = resolverF.getExceptionCacheResolver(pctx).resolveCache(pctx);
if (shouldICache(annotation.cachedExceptions(), annotation.nonCachedExceptions(), e, true)) {
exceptionCache.put(key, e);
}
}
throw e;
}
return result;
}
use of javax.cache.annotation.GeneratedCacheKey in project Payara by payara.
the class CacheRemoveInterceptor method doRemove.
private void doRemove(PayaraCacheKeyInvocationContext<CacheRemove> pctx) {
CacheKeyGenerator generator = pctx.getGenerator();
CacheResolverFactory resolverF = pctx.getFactory();
CacheResolver cacheResolver = resolverF.getCacheResolver(pctx);
Cache cache = cacheResolver.resolveCache(pctx);
GeneratedCacheKey key = generator.generateCacheKey(pctx);
cache.remove(key);
}
Aggregations