Polishing

This commit is contained in:
Juergen Hoeller
2015-08-26 11:04:14 +02:00
parent 91b473fec5
commit e05fb494f5
6 changed files with 41 additions and 46 deletions

View File

@@ -60,6 +60,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
*/
private final static Collection<CacheOperation> NULL_CACHING_ATTRIBUTE = Collections.emptyList();
/**
* Logger available to subclasses.
* <p>As this base class is not marked Serializable, the logger will be recreated
@@ -68,13 +69,14 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
protected final Log logger = LogFactory.getLog(getClass());
/**
* Cache of CacheOperations, keyed by {@link MethodCacheKey} (Method + target Class).
* Cache of CacheOperations, keyed by {@link AnnotatedElementKey}.
* <p>As this base class is not marked Serializable, the cache will be recreated
* after serialization - provided that the concrete subclass is Serializable.
*/
final Map<Object, Collection<CacheOperation>> attributeCache =
private final Map<Object, Collection<CacheOperation>> attributeCache =
new ConcurrentHashMap<Object, Collection<CacheOperation>>(1024);
/**
* Determine the caching attribute for this method invocation.
* <p>Defaults to the class's caching attribute if no method attribute is found.
@@ -85,30 +87,23 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
*/
@Override
public Collection<CacheOperation> getCacheOperations(Method method, Class<?> targetClass) {
// First, see if we have a cached value.
Object cacheKey = getCacheKey(method, targetClass);
Collection<CacheOperation> cached = this.attributeCache.get(cacheKey);
if (cached != null) {
if (cached == NULL_CACHING_ATTRIBUTE) {
return null;
}
// Value will either be canonical value indicating there is no caching attribute,
// or an actual caching attribute.
return cached;
return (cached != NULL_CACHING_ATTRIBUTE ? cached : null);
}
else {
// We need to work it out.
Collection<CacheOperation> cacheOps = computeCacheOperations(method, targetClass);
// Put it in the cache.
if (cacheOps == null) {
this.attributeCache.put(cacheKey, NULL_CACHING_ATTRIBUTE);
}
else {
if (cacheOps != null) {
if (logger.isDebugEnabled()) {
logger.debug("Adding cacheable method '" + method.getName() + "' with attribute: " + cacheOps);
}
this.attributeCache.put(cacheKey, cacheOps);
}
else {
this.attributeCache.put(cacheKey, NULL_CACHING_ATTRIBUTE);
}
return cacheOps;
}
}
@@ -187,4 +182,5 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
protected boolean allowPublicMethodsOnly() {
return false;
}
}