Search in sources :

Example 1 with KeyGenerator

use of cn.taketoday.cache.interceptor.KeyGenerator in project today-infrastructure by TAKETODAY.

the class AnnotationJCacheOperationSource method createCacheRemoveOperation.

protected CacheRemoveOperation createCacheRemoveOperation(Method method, @Nullable CacheDefaults defaults, CacheRemove ann) {
    String cacheName = determineCacheName(method, defaults, ann.cacheName());
    CacheResolverFactory cacheResolverFactory = determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
    KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());
    CacheMethodDetails<CacheRemove> methodDetails = createMethodDetails(method, ann, cacheName);
    CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
    return new CacheRemoveOperation(methodDetails, cacheResolver, keyGenerator);
}
Also used : CacheRemove(javax.cache.annotation.CacheRemove) CacheResolver(cn.taketoday.cache.interceptor.CacheResolver) CacheKeyGenerator(javax.cache.annotation.CacheKeyGenerator) KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator) CacheResolverFactory(javax.cache.annotation.CacheResolverFactory)

Example 2 with KeyGenerator

use of cn.taketoday.cache.interceptor.KeyGenerator in project today-infrastructure by TAKETODAY.

the class AnnotationJCacheOperationSource method createCacheResultOperation.

protected CacheResultOperation createCacheResultOperation(Method method, @Nullable 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);
}
Also used : CacheResult(javax.cache.annotation.CacheResult) CacheResolver(cn.taketoday.cache.interceptor.CacheResolver) CacheKeyGenerator(javax.cache.annotation.CacheKeyGenerator) KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator) CacheResolverFactory(javax.cache.annotation.CacheResolverFactory)

Example 3 with KeyGenerator

use of cn.taketoday.cache.interceptor.KeyGenerator in project today-infrastructure by TAKETODAY.

the class AnnotationJCacheOperationSource method createCachePutOperation.

protected CachePutOperation createCachePutOperation(Method method, @Nullable CacheDefaults defaults, CachePut ann) {
    String cacheName = determineCacheName(method, defaults, ann.cacheName());
    CacheResolverFactory cacheResolverFactory = determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
    KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());
    CacheMethodDetails<CachePut> methodDetails = createMethodDetails(method, ann, cacheName);
    CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
    return new CachePutOperation(methodDetails, cacheResolver, keyGenerator);
}
Also used : CacheResolver(cn.taketoday.cache.interceptor.CacheResolver) CacheKeyGenerator(javax.cache.annotation.CacheKeyGenerator) KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator) CachePut(javax.cache.annotation.CachePut) CacheResolverFactory(javax.cache.annotation.CacheResolverFactory)

Example 4 with KeyGenerator

use of cn.taketoday.cache.interceptor.KeyGenerator in project today-infrastructure by TAKETODAY.

the class AbstractKeyCacheInterceptor method generateKey.

/**
 * Generate a key for the specified invocation.
 *
 * @param context the context of the invocation
 * @return the key to use
 */
protected Object generateKey(CacheOperationInvocationContext<O> context) {
    KeyGenerator keyGenerator = context.getOperation().getKeyGenerator();
    Object key = keyGenerator.generate(context.getTarget(), context.getMethod(), context.getArgs());
    if (logger.isTraceEnabled()) {
        logger.trace("Computed cache key {} for operation {}", key, context.getOperation());
    }
    return key;
}
Also used : KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator)

Example 5 with KeyGenerator

use of cn.taketoday.cache.interceptor.KeyGenerator in project today-framework by TAKETODAY.

the class AbstractKeyCacheInterceptor method generateKey.

/**
 * Generate a key for the specified invocation.
 *
 * @param context the context of the invocation
 * @return the key to use
 */
protected Object generateKey(CacheOperationInvocationContext<O> context) {
    KeyGenerator keyGenerator = context.getOperation().getKeyGenerator();
    Object key = keyGenerator.generate(context.getTarget(), context.getMethod(), context.getArgs());
    if (logger.isTraceEnabled()) {
        logger.trace("Computed cache key {} for operation {}", key, context.getOperation());
    }
    return key;
}
Also used : KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator)

Aggregations

KeyGenerator (cn.taketoday.cache.interceptor.KeyGenerator)10 CacheResolver (cn.taketoday.cache.interceptor.CacheResolver)6 CacheKeyGenerator (javax.cache.annotation.CacheKeyGenerator)6 CacheResolverFactory (javax.cache.annotation.CacheResolverFactory)6 CacheInterceptor (cn.taketoday.cache.interceptor.CacheInterceptor)2 SomeCustomKeyGenerator (cn.taketoday.contextsupport.testfixture.cache.SomeCustomKeyGenerator)2 SomeKeyGenerator (cn.taketoday.contextsupport.testfixture.cache.SomeKeyGenerator)2 CachePut (javax.cache.annotation.CachePut)2 CacheRemove (javax.cache.annotation.CacheRemove)2 CacheResult (javax.cache.annotation.CacheResult)2 Test (org.junit.jupiter.api.Test)2