Skip to content

Commit 67f1842

Browse files
committed
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
1 parent b0a72b3 commit 67f1842

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,10 @@ private boolean isConditionPassing(CacheOperationContext context, Object result)
477477

478478
private Object generateKey(CacheOperationContext context, Object result) {
479479
Object key = context.generateKey(result);
480-
Assert.notNull(key, "Null key returned for cache operation (maybe you are using named params " +
481-
"on classes without debug info?) " + context.metadata.operation);
480+
if (key == null) {
481+
throw new IllegalArgumentException("Null key returned for cache operation (maybe you are " +
482+
"using named params on classes without debug info?) " + context.metadata.operation);
483+
}
482484
if (logger.isTraceEnabled()) {
483485
logger.trace("Computed cache key " + key + " for operation " + context.metadata.operation);
484486
}

0 commit comments

Comments
 (0)