Add cache-related logs

Add a trace log for cache hit and cache miss events.

Issue: SPR-11654
This commit is contained in:
Stephane Nicoll 2015-04-07 14:27:43 +02:00
parent 6f3570a0f6
commit 6bc14cc7ae
1 changed files with 24 additions and 1 deletions

View File

@ -435,6 +435,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
if (cached != null) {
return cached;
}
else {
if (logger.isTraceEnabled()) {
logger.trace("No cache entry for key '" + key + "' in cache(s) " + context.getCacheNames());
}
}
}
}
return null;
@ -462,6 +467,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
for (Cache cache : context.getCaches()) {
Cache.ValueWrapper wrapper = doGet(cache, key);
if (wrapper != null) {
if (logger.isTraceEnabled()) {
logger.trace("Cache entry for key '" + key + "' found in cache '" + cache.getName() + "'");
}
return wrapper;
}
}
@ -484,7 +492,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
"using named params on classes without debug info?) " + context.metadata.operation);
}
if (logger.isTraceEnabled()) {
logger.trace("Computed cache key " + key + " for operation " + context.metadata.operation);
logger.trace("Computed cache key '" + key + "' for operation " + context.metadata.operation);
}
return key;
}
@ -548,6 +556,8 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
private final Collection<? extends Cache> caches;
private final Collection<String> cacheNames;
private final AnnotatedElementKey methodCacheKey;
public CacheOperationContext(CacheOperationMetadata metadata, Object[] args, Object target) {
@ -555,6 +565,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
this.args = extractArgs(metadata.method, args);
this.target = target;
this.caches = CacheAspectSupport.this.getCaches(this, metadata.cacheResolver);
this.cacheNames = createCacheNames(this.caches);
this.methodCacheKey = new AnnotatedElementKey(metadata.method, metadata.targetClass);
}
@ -633,6 +644,18 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
protected Collection<? extends Cache> getCaches() {
return this.caches;
}
protected Collection<String> getCacheNames() {
return this.cacheNames;
}
private Collection<String> createCacheNames(Collection<? extends Cache> caches) {
Collection<String> names = new ArrayList<String>();
for (Cache cache : caches) {
names.add(cache.getName());
}
return names;
}
}