@@ -379,7 +379,7 @@ private Object execute(final CacheOperationInvoker invoker, Method method, Cache
379379 Object key = generateKey (context , CacheOperationExpressionEvaluator .NO_RESULT );
380380 Cache cache = context .getCaches ().iterator ().next ();
381381 try {
382- return wrapCacheValue (method , cache . get ( key , () -> unwrapReturnValue ( invokeOperation ( invoker )) ));
382+ return wrapCacheValue (method , handleSynchronizedGet ( invoker , key , cache ));
383383 }
384384 catch (Cache .ValueRetrievalException ex ) {
385385 // Directly propagate ThrowableWrapper from the invoker,
@@ -436,6 +436,22 @@ private Object execute(final CacheOperationInvoker invoker, Method method, Cache
436436 return returnValue ;
437437 }
438438
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+
439455 @ Nullable
440456 private Object wrapCacheValue (Method method , @ Nullable Object cacheValue ) {
441457 if (method .getReturnType () == Optional .class &&
@@ -869,4 +885,13 @@ public int compareTo(CacheOperationCacheKey other) {
869885 }
870886 }
871887
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+
872897}
0 commit comments