Example usage for org.springframework.cache.interceptor CacheOperation getKeyGenerator

List of usage examples for org.springframework.cache.interceptor CacheOperation getKeyGenerator

Introduction

In this page you can find the example usage for org.springframework.cache.interceptor CacheOperation getKeyGenerator.

Prototype

public String getKeyGenerator() 

Source Link

Usage

From source file:org.springframework.cache.interceptor.CacheAspectSupport.java

/**
 * Return the {@link CacheOperationMetadata} for the specified operation.
 * <p>Resolve the {@link CacheResolver} and the {@link KeyGenerator} to be
 * used for the operation.//from   w  ww  . j  a  va 2  s. com
 * @param operation the operation
 * @param method the method on which the operation is invoked
 * @param targetClass the target type
 * @return the resolved metadata for the operation
 */
protected CacheOperationMetadata getCacheOperationMetadata(CacheOperation operation, Method method,
        Class<?> targetClass) {

    CacheOperationCacheKey cacheKey = new CacheOperationCacheKey(operation, method, targetClass);
    CacheOperationMetadata metadata = this.metadataCache.get(cacheKey);
    if (metadata == null) {
        KeyGenerator operationKeyGenerator;
        if (StringUtils.hasText(operation.getKeyGenerator())) {
            operationKeyGenerator = getBean(operation.getKeyGenerator(), KeyGenerator.class);
        } else {
            operationKeyGenerator = getKeyGenerator();
        }
        CacheResolver operationCacheResolver;
        if (StringUtils.hasText(operation.getCacheResolver())) {
            operationCacheResolver = getBean(operation.getCacheResolver(), CacheResolver.class);
        } else if (StringUtils.hasText(operation.getCacheManager())) {
            CacheManager cacheManager = getBean(operation.getCacheManager(), CacheManager.class);
            operationCacheResolver = new SimpleCacheResolver(cacheManager);
        } else {
            operationCacheResolver = getCacheResolver();
            Assert.state(operationCacheResolver != null, "No CacheResolver/CacheManager set");
        }
        metadata = new CacheOperationMetadata(operation, method, targetClass, operationKeyGenerator,
                operationCacheResolver);
        this.metadataCache.put(cacheKey, metadata);
    }
    return metadata;
}