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