@@ -379,7 +379,7 @@ private Object execute(final CacheOperationInvoker invoker, Method method, Cache
379
379
Object key = generateKey (context , CacheOperationExpressionEvaluator .NO_RESULT );
380
380
Cache cache = context .getCaches ().iterator ().next ();
381
381
try {
382
- return wrapCacheValue (method , cache . get ( key , () -> unwrapReturnValue ( invokeOperation ( invoker )) ));
382
+ return wrapCacheValue (method , handleSynchronizedGet ( invoker , key , cache ));
383
383
}
384
384
catch (Cache .ValueRetrievalException ex ) {
385
385
// Directly propagate ThrowableWrapper from the invoker,
@@ -436,6 +436,22 @@ private Object execute(final CacheOperationInvoker invoker, Method method, Cache
436
436
return returnValue ;
437
437
}
438
438
439
+ @ Nullable
440
+ private Object handleSynchronizedGet (CacheOperationInvoker invoker , Object key , Cache cache ) {
441
+ InvocationAwareResult invocationResult = new InvocationAwareResult ();
442
+ Object result = cache .get (key , () -> {
443
+ invocationResult .invoked = true ;
444
+ if (logger .isTraceEnabled ()) {
445
+ logger .trace ("No cache entry for key '" + key + "' in cache " + cache .getName ());
446
+ }
447
+ return unwrapReturnValue (invokeOperation (invoker ));
448
+ });
449
+ if (!invocationResult .invoked && logger .isTraceEnabled ()) {
450
+ logger .trace ("Cache entry for key '" + key + "' found in cache '" + cache .getName () + "'" );
451
+ }
452
+ return result ;
453
+ }
454
+
439
455
@ Nullable
440
456
private Object wrapCacheValue (Method method , @ Nullable Object cacheValue ) {
441
457
if (method .getReturnType () == Optional .class &&
@@ -869,4 +885,13 @@ public int compareTo(CacheOperationCacheKey other) {
869
885
}
870
886
}
871
887
888
+ /**
889
+ * Internal holder class for recording that a cache method was invoked.
890
+ */
891
+ private static class InvocationAwareResult {
892
+
893
+ boolean invoked ;
894
+
895
+ }
896
+
872
897
}
0 commit comments