use of javax.cache.annotation.CacheResolver 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.CacheResolver 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.CacheResolver in project spring-framework by spring-projects.
the class CacheResolverAdapterTests method getCacheResolver.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected CacheResolver getCacheResolver(CacheInvocationContext<? extends Annotation> context, String cacheName) {
CacheResolver cacheResolver = mock(CacheResolver.class);
javax.cache.Cache cache;
if (cacheName == null) {
cache = null;
} else {
cache = mock(javax.cache.Cache.class);
given(cache.getName()).willReturn(cacheName);
}
given(cacheResolver.resolveCache(context)).willReturn(cache);
return cacheResolver;
}
use of javax.cache.annotation.CacheResolver in project Payara by payara.
the class CacheRemoveAllInterceptor method doRemoveAll.
private void doRemoveAll(PayaraCacheKeyInvocationContext<CacheRemoveAll> pctx) {
CacheResolverFactory resolverF = pctx.getFactory();
CacheResolver cacheResolver = resolverF.getCacheResolver(pctx);
Cache cache = cacheResolver.resolveCache(pctx);
cache.removeAll();
}
use of javax.cache.annotation.CacheResolver 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