parent
eb4b68ffda
commit
a3a0e5165c
|
|
@ -154,6 +154,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
|||
targetClass = target.getClass();
|
||||
}
|
||||
|
||||
boolean log = logger.isTraceEnabled();
|
||||
|
||||
final CacheDefinition cacheDef = getCacheDefinitionSource().getCacheDefinition(method, targetClass);
|
||||
|
||||
Object retVal = null;
|
||||
|
|
@ -168,8 +170,14 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
|||
if (cacheDef instanceof CacheUpdateDefinition) {
|
||||
Object key = context.generateKey();
|
||||
|
||||
if (log) {
|
||||
logger.trace("Computed cache key " + key + " for definition " + cacheDef);
|
||||
}
|
||||
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("Null key returned for cache definition " + cacheDef);
|
||||
throw new IllegalArgumentException(
|
||||
"Null key returned for cache definition (maybe you are using named params on classes without debug info?) "
|
||||
+ cacheDef);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -185,8 +193,16 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
|||
retVal = cache.get(key);
|
||||
// to avoid race-conditions of entries being removed between contains/get calls
|
||||
if (cache.containsKey(key)) {
|
||||
if (log) {
|
||||
logger.trace("Key " + key + " found in cache, returning value " + retVal);
|
||||
}
|
||||
return retVal;
|
||||
} else {
|
||||
if (log) {
|
||||
logger.trace("Key " + key + " NOT found in cache, invoking target method for caching "
|
||||
+ method);
|
||||
}
|
||||
|
||||
retVal = invocation.call();
|
||||
cache.put(key, retVal);
|
||||
}
|
||||
|
|
@ -225,8 +241,17 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
|||
}
|
||||
|
||||
if (!cacheHit) {
|
||||
if (log) {
|
||||
logger.trace("Key " + key + " NOT found in cache(s), invoking cached target method "
|
||||
+ method);
|
||||
}
|
||||
retVal = invocation.call();
|
||||
}
|
||||
else {
|
||||
if (log) {
|
||||
logger.trace("Key " + key + " found in cache, returning value " + retVal);
|
||||
}
|
||||
}
|
||||
|
||||
// update all caches (if needed)
|
||||
for (Cache cache : caches) {
|
||||
|
|
@ -247,11 +272,19 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
|||
// flush the cache (ignore arguments)
|
||||
if (invalidateDef.isCacheWide()) {
|
||||
cache.clear();
|
||||
if (log) {
|
||||
logger.trace("Invalidating entire cache for definition " + cacheDef + " on method "
|
||||
+ method);
|
||||
}
|
||||
} else {
|
||||
// check key
|
||||
if (key == null) {
|
||||
key = context.generateKey();
|
||||
}
|
||||
if (log) {
|
||||
logger.trace("Invalidating cache key " + key + " for definition " + cacheDef
|
||||
+ " on method " + method);
|
||||
}
|
||||
cache.remove(key);
|
||||
}
|
||||
}
|
||||
|
|
@ -259,6 +292,11 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
|||
|
||||
return retVal;
|
||||
}
|
||||
else {
|
||||
if (log) {
|
||||
logger.trace("Cache condition failed on method " + method + " for definition " + cacheDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return invocation.call();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ import org.aopalliance.intercept.MethodInvocation;
|
|||
@SuppressWarnings("serial")
|
||||
public class CacheInterceptor extends CacheAspectSupport implements MethodInterceptor, Serializable {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
||||
Method method = invocation.getMethod();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue