use of javax.cache.annotation.CacheResult in project spring-framework by spring-projects.
the class AnnotationJCacheOperationSource method createCacheResultOperation.
protected CacheResultOperation createCacheResultOperation(Method method, CacheDefaults defaults, CacheResult ann) {
String cacheName = determineCacheName(method, defaults, ann.cacheName());
CacheResolverFactory cacheResolverFactory = determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());
CacheMethodDetails<CacheResult> methodDetails = createMethodDetails(method, ann, cacheName);
CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
CacheResolver exceptionCacheResolver = null;
final String exceptionCacheName = ann.exceptionCacheName();
if (StringUtils.hasText(exceptionCacheName)) {
exceptionCacheResolver = getExceptionCacheResolver(cacheResolverFactory, methodDetails);
}
return new CacheResultOperation(methodDetails, cacheResolver, keyGenerator, exceptionCacheResolver);
}
use of javax.cache.annotation.CacheResult in project spring-framework by spring-projects.
the class AnnotationJCacheOperationSource method findCacheOperation.
@Override
protected JCacheOperation<?> findCacheOperation(Method method, Class<?> targetType) {
CacheResult cacheResult = method.getAnnotation(CacheResult.class);
CachePut cachePut = method.getAnnotation(CachePut.class);
CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class);
CacheRemoveAll cacheRemoveAll = method.getAnnotation(CacheRemoveAll.class);
int found = countNonNull(cacheResult, cachePut, cacheRemove, cacheRemoveAll);
if (found == 0) {
return null;
}
if (found > 1) {
throw new IllegalStateException("More than one cache annotation found on '" + method + "'");
}
CacheDefaults defaults = getCacheDefaults(method, targetType);
if (cacheResult != null) {
return createCacheResultOperation(method, defaults, cacheResult);
} else if (cachePut != null) {
return createCachePutOperation(method, defaults, cachePut);
} else if (cacheRemove != null) {
return createCacheRemoveOperation(method, defaults, cacheRemove);
} else {
return createCacheRemoveAllOperation(method, defaults, cacheRemoveAll);
}
}
use of javax.cache.annotation.CacheResult in project spring-framework by spring-projects.
the class CacheResolverAdapterTests method createDummyContext.
protected DefaultCacheInvocationContext<?> createDummyContext() throws Exception {
Method method = Sample.class.getMethod("get", String.class);
CacheResult cacheAnnotation = method.getAnnotation(CacheResult.class);
CacheMethodDetails<CacheResult> methodDetails = new DefaultCacheMethodDetails<>(method, cacheAnnotation, "test");
CacheResultOperation operation = new CacheResultOperation(methodDetails, defaultCacheResolver, defaultKeyGenerator, defaultExceptionCacheResolver);
return new DefaultCacheInvocationContext<>(operation, new Sample(), new Object[] { "id" });
}
Aggregations