@Override public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) { if (!(context instanceof CacheInvocationContext<?>)) { throw new IllegalStateException("Unexpected context " + context); } CacheInvocationContext<?> cacheInvocationContext = (CacheInvocationContext<?>) context; javax.cache.Cache<Object, Object> cache = this.target.resolveCache(cacheInvocationContext); if (cache == null) { throw new IllegalStateException("Could not resolve cache for " + context + " using " + this.target); } return Collections.singleton(new JCacheCache(cache)); }
@Override public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) { if (!(context instanceof CacheInvocationContext<?>)) { throw new IllegalStateException("Unexpected context " + context); } CacheInvocationContext<?> cacheInvocationContext = (CacheInvocationContext<?>) context; javax.cache.Cache<Object, Object> cache = this.target.resolveCache(cacheInvocationContext); if (cache == null) { throw new IllegalStateException("Could not resolve cache for " + context + " using " + this.target); } return Collections.singleton(new JCacheCache(cache)); }
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; }
@Override public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) { if (!(context instanceof CacheInvocationContext<?>)) { throw new IllegalStateException("Unexpected context " + context); } CacheInvocationContext<?> cacheInvocationContext = (CacheInvocationContext<?>) context; javax.cache.Cache<Object, Object> cache = this.target.resolveCache(cacheInvocationContext); if (cache == null) { throw new IllegalStateException("Could not resolve cache for " + context + " using " + this.target); } return Collections.singleton(new JCacheCache(cache)); }
/** * Get the exception cache if one is configured * * @param cacheKeyInvocationContext The invocation details * @param methodDetails The method details * @return The exception cache, null if exception caching is disabled. */ protected Cache<Object, Throwable> getExceptionCache( final InternalCacheKeyInvocationContext<? extends Annotation> cacheKeyInvocationContext, final CacheResultMethodDetails methodDetails) { final CacheResolver exceptionCacheResolver = methodDetails.getExceptionCacheResolver(); if (exceptionCacheResolver != null) { return exceptionCacheResolver.resolveCache(cacheKeyInvocationContext); } return null; } }
/** * Resolve the Cache and call removeAll * * @param cacheInvocationContext The invocation context * @param methodDetails The details about the cached method */ protected void removeAll(final InternalCacheInvocationContext<? extends Annotation> cacheInvocationContext, final StaticCacheInvocationContext<CacheRemoveAll> methodDetails) { final CacheResolver cacheResolver = methodDetails.getCacheResolver(); final Cache<Object, Object> cache = cacheResolver.resolveCache(cacheInvocationContext); cache.removeAll(); }
private void removeAll(final CacheKeyInvocationContext<CacheRemoveAll> context, final CacheDefaults defaults, final CacheRemoveAll cacheRemoveAll) { final Cache<Object, Object> cache = helper.cacheResolverFactoryFor(defaults, cacheRemoveAll.cacheResolverFactory()).getCacheResolver(context).resolveCache(context); cache.removeAll(); } }
/** * Remove entry from cache * * @param cacheKeyInvocationContext The invocation context * @param methodDetails The details about the cached method */ private void cacheRemove(final InternalCacheKeyInvocationContext<? extends Annotation> cacheKeyInvocationContext, final CacheRemoveEntryMethodDetails methodDetails) { final CacheResolver cacheResolver = methodDetails.getCacheResolver(); final Cache<Object, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); final CacheKeyGenerator cacheKeyGenerator = methodDetails.getCacheKeyGenerator(); final GeneratedCacheKey cacheKey = cacheKeyGenerator.generateCacheKey(cacheKeyInvocationContext); cache.remove(cacheKey); } }
/** * Lookup the Cache, generate a GeneratedCacheKey and store the value in the cache. * * @param cacheKeyInvocationContext The invocation context * @param methodDetails The details about the cached method * @param value The value to cache */ protected void cacheValue(final InternalCacheKeyInvocationContext<? extends Annotation> cacheKeyInvocationContext, final CachePutMethodDetails methodDetails, final Object value) { final Object cachedValue = value; final CacheResolver cacheResolver = methodDetails.getCacheResolver(); final Cache<Object, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); final CacheKeyGenerator cacheKeyGenerator = methodDetails.getCacheKeyGenerator(); final GeneratedCacheKey cacheKey = cacheKeyGenerator.generateCacheKey(cacheKeyInvocationContext); cache.put(cacheKey, cachedValue); } }
private void doRemove(final CacheKeyInvocationContext<CacheRemove> context, final CacheDefaults defaults, final CacheRemove cacheRemove) { final Cache<Object, Object> cache = helper.cacheResolverFactoryFor(defaults, cacheRemove.cacheResolverFactory()).getCacheResolver(context).resolveCache(context); final GeneratedCacheKey key = helper.cacheKeyGeneratorFor(defaults, cacheRemove.cacheKeyGenerator()).generateCacheKey(context); cache.remove(key); } }
final Cache<Object, Object> cache = cacheResolver.resolveCache(context); exceptionCache = cacheResolverFactory.getExceptionCacheResolver(context).resolveCache(context); final Object exception = exceptionCache.get(cacheKey); if (exception != null) { if (helper.isIncluded(t.getClass(), cacheResult.cachedExceptions(), cacheResult.nonCachedExceptions())) { if (exceptionCache == null) { exceptionCache = cacheResolverFactory.getExceptionCacheResolver(context).resolveCache(context);
final Cache<Object, Object> cache = cacheResolver.resolveCache(context); exceptionCache = cacheResolverFactory.getExceptionCacheResolver(context).resolveCache(context); final Object exception = exceptionCache.get(cacheKey); if (exception != null) exceptionCache = cacheResolverFactory.getExceptionCacheResolver(context).resolveCache(context);
final Cache<Object, Object> cache = cacheResolver.resolveCache(context); exceptionCache = cacheResolverFactory.getExceptionCacheResolver(context).resolveCache(context); final Object exception = exceptionCache.get(cacheKey); if (exception != null) exceptionCache = cacheResolverFactory.getExceptionCacheResolver(context).resolveCache(context);
private void doCache(final CacheKeyInvocationContext<CachePut> context, final CacheDefaults defaults, final CachePut cachePut) { final Cache<Object, Object> cache = helper.cacheResolverFactoryFor(defaults, cachePut.cacheResolverFactory()).getCacheResolver(context).resolveCache(context); final GeneratedCacheKey key = helper.cacheKeyGeneratorFor(defaults, cachePut.cacheKeyGenerator()).generateCacheKey(context); cache.put(key, context.getValueParameter().getValue()); } }
methodMeta.getCacheRemoveAll(), cacheName, methodMeta); final CacheResolver cacheResolver = cacheResolverFactory.getCacheResolver(context); final Cache<Object, Object> cache = cacheResolver.resolveCache(context);
methodMeta.getCacheRemove(), cacheName, methodMeta); final CacheResolver cacheResolver = cacheResolverFactory.getCacheResolver(context); final Cache<Object, Object> cache = cacheResolver.resolveCache(context);
ic, methodMeta.getCacheRemoveAll(), cacheName, methodMeta); final CacheResolver cacheResolver = cacheResolverFactory.getCacheResolver(context); final Cache<Object, Object> cache = cacheResolver.resolveCache(context);
ic, methodMeta.getCacheRemove(), cacheName, methodMeta); final CacheResolver cacheResolver = cacheResolverFactory.getCacheResolver(context); final Cache<Object, Object> cache = cacheResolver.resolveCache(context);
methodMeta.getCachePut(), cacheName, methodMeta); final CacheResolver cacheResolver = cacheResolverFactory.getCacheResolver(context); final Cache<Object, Object> cache = cacheResolver.resolveCache(context);
ic, methodMeta.getCachePut(), cacheName, methodMeta); final CacheResolver cacheResolver = cacheResolverFactory.getCacheResolver(context); final Cache<Object, Object> cache = cacheResolver.resolveCache(context);