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
This commit is contained in:
Stephane Nicoll 2014-12-10 14:34:11 +01:00
parent b0a72b311f
commit 67f184293b
1 changed files with 4 additions and 2 deletions

View File

@ -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);
}