Add cache-related logs
Add a trace log for cache hit and cache miss events. Issue: SPR-11654
This commit is contained in:
parent
6f3570a0f6
commit
6bc14cc7ae
|
@ -435,6 +435,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (logger.isTraceEnabled()) {
|
||||||
|
logger.trace("No cache entry for key '" + key + "' in cache(s) " + context.getCacheNames());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -462,6 +467,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||||
for (Cache cache : context.getCaches()) {
|
for (Cache cache : context.getCaches()) {
|
||||||
Cache.ValueWrapper wrapper = doGet(cache, key);
|
Cache.ValueWrapper wrapper = doGet(cache, key);
|
||||||
if (wrapper != null) {
|
if (wrapper != null) {
|
||||||
|
if (logger.isTraceEnabled()) {
|
||||||
|
logger.trace("Cache entry for key '" + key + "' found in cache '" + cache.getName() + "'");
|
||||||
|
}
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -484,7 +492,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||||
"using named params on classes without debug info?) " + context.metadata.operation);
|
"using named params on classes without debug info?) " + context.metadata.operation);
|
||||||
}
|
}
|
||||||
if (logger.isTraceEnabled()) {
|
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;
|
return key;
|
||||||
}
|
}
|
||||||
|
@ -548,6 +556,8 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||||
|
|
||||||
private final Collection<? extends Cache> caches;
|
private final Collection<? extends Cache> caches;
|
||||||
|
|
||||||
|
private final Collection<String> cacheNames;
|
||||||
|
|
||||||
private final AnnotatedElementKey methodCacheKey;
|
private final AnnotatedElementKey methodCacheKey;
|
||||||
|
|
||||||
public CacheOperationContext(CacheOperationMetadata metadata, Object[] args, Object target) {
|
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.args = extractArgs(metadata.method, args);
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.caches = CacheAspectSupport.this.getCaches(this, metadata.cacheResolver);
|
this.caches = CacheAspectSupport.this.getCaches(this, metadata.cacheResolver);
|
||||||
|
this.cacheNames = createCacheNames(this.caches);
|
||||||
this.methodCacheKey = new AnnotatedElementKey(metadata.method, metadata.targetClass);
|
this.methodCacheKey = new AnnotatedElementKey(metadata.method, metadata.targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,6 +644,18 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||||
protected Collection<? extends Cache> getCaches() {
|
protected Collection<? extends Cache> getCaches() {
|
||||||
return this.caches;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue