use of fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext in project Payara by payara.
the class CachePutInterceptor method cachePut.
@AroundInvoke
public Object cachePut(InvocationContext ctx) throws Throwable {
if (!isEnabled()) {
return ctx.proceed();
}
CachePut annotation = ctx.getMethod().getAnnotation(CachePut.class);
PayaraCacheKeyInvocationContext<CachePut> pctx = new PayaraCacheKeyInvocationContext<>(ctx, annotation);
if (!annotation.afterInvocation()) {
doPut(pctx);
}
Object result = null;
try {
result = ctx.proceed();
} catch (Throwable e) {
if (annotation.afterInvocation()) {
if (shouldICache(annotation.cacheFor(), annotation.noCacheFor(), e, false)) {
doPut(pctx);
}
}
throw e;
}
if (annotation.afterInvocation()) {
doPut(pctx);
}
return result;
}
use of fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext in project Payara by payara.
the class CacheRemoveInterceptor method cacheRemove.
@AroundInvoke
public Object cacheRemove(InvocationContext ctx) throws Throwable {
if (!isEnabled()) {
return ctx.proceed();
}
CacheRemove annotation = ctx.getMethod().getAnnotation(CacheRemove.class);
PayaraCacheKeyInvocationContext<CacheRemove> pctx = new PayaraCacheKeyInvocationContext<>(ctx, annotation);
if (!annotation.afterInvocation()) {
doRemove(pctx);
}
Object result = null;
try {
result = ctx.proceed();
} catch (Throwable e) {
if (annotation.afterInvocation()) {
if (shouldIEvict(annotation.evictFor(), annotation.noEvictFor(), e)) {
doRemove(pctx);
}
}
throw e;
}
if (annotation.afterInvocation()) {
doRemove(pctx);
}
return result;
}
use of fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext 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 fish.payara.cdi.jsr107.implementation.PayaraCacheKeyInvocationContext in project Payara by payara.
the class CacheRemoveAllInterceptor method cacheRemoveAll.
@AroundInvoke
public Object cacheRemoveAll(InvocationContext ctx) throws Throwable {
if (!isEnabled()) {
return ctx.proceed();
}
CacheRemoveAll annotation = ctx.getMethod().getAnnotation(CacheRemoveAll.class);
PayaraCacheKeyInvocationContext<CacheRemoveAll> pctx = new PayaraCacheKeyInvocationContext<>(ctx, annotation);
if (!annotation.afterInvocation()) {
doRemoveAll(pctx);
}
Object result = null;
try {
result = ctx.proceed();
} catch (Throwable e) {
if (annotation.afterInvocation()) {
if (shouldIEvict(annotation.evictFor(), annotation.noEvictFor(), e)) {
doRemoveAll(pctx);
}
}
throw e;
}
if (annotation.afterInvocation()) {
doRemoveAll(pctx);
}
return result;
}
Aggregations