Example usage for org.springframework.cache.interceptor SimpleCacheResolver SimpleCacheResolver

List of usage examples for org.springframework.cache.interceptor SimpleCacheResolver SimpleCacheResolver

Introduction

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

Prototype

public SimpleCacheResolver(CacheManager cacheManager) 

Source Link

Document

Construct a new SimpleCacheResolver for the given CacheManager .

Usage

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

/**
 * Set the {@link CacheManager} to use to create a default {@link CacheResolver}.
 * Replace the current {@link CacheResolver}, if any.
 * @see #setCacheResolver//from  w  w w.  j  a va  2 s.  c  om
 * @see SimpleCacheResolver
 */
public void setCacheManager(CacheManager cacheManager) {
    this.cacheResolver = new SimpleCacheResolver(cacheManager);
}

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  ava 2 s .c  o m*/
 * @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;
}