Browse Source

Improve performance of generateKey

Only compute the error message to display when the generated key is
actually null instead of using Assert.notNull as the cache operation
'toString()' method is non trivial and gets computed regardless of the
result.

Issue: SPR-12527
pull/930/head
Stephane Nicoll 10 years ago
parent
commit
67f184293b
  1. 6
      spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java

6
spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java vendored

@ -477,8 +477,10 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker @@ -477,8 +477,10 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
private Object generateKey(CacheOperationContext context, Object result) {
Object key = context.generateKey(result);
Assert.notNull(key, "Null key returned for cache operation (maybe you are using named params " +
"on classes without debug info?) " + context.metadata.operation);
if (key == null) {
throw new IllegalArgumentException("Null key returned for cache operation (maybe you are " +
"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);
}

Loading…
Cancel
Save