@@ -8403,6 +8403,33 @@ result in an exception as a custom `CacheManager` will be ignored by the
8403
8403
`CacheResolver` implementation. This is probably not what you expect.
8404
8404
====
8405
8405
8406
+ [[cache-annotations-cacheable-synchronized]]
8407
+ ===== Synchronized caching
8408
+ In a multi-threaded environment, certain operations might be concurrently invoked for
8409
+ the same argument (typically on startup). By default, the cache abstraction does not
8410
+ lock anything and the same value may be computed several times, defeating the purpose
8411
+ of caching.
8412
+
8413
+ For those particular cases, the `sync` attribute can be used to instruct the underlying
8414
+ cache provider to _lock_ the cache entry while the value is being computed. As a result,
8415
+ only one thread will be busy computing the value while the others are blocked until the
8416
+ entry is updated in the cache.
8417
+
8418
+ [source,java,indent=0]
8419
+ [subs="verbatim,quotes"]
8420
+ ----
8421
+ @Cacheable(cacheNames="foos", **sync="true"**)
8422
+ public Foo executeExpensiveOperation(String id) {...}
8423
+ ----
8424
+
8425
+ [NOTE]
8426
+ ====
8427
+ This is an optional feature and your favorite cache library may not support it. All
8428
+ `CacheManager` implementations provided by the core framework support it. Check the
8429
+ documentation of your cache provider for more details.
8430
+ ====
8431
+
8432
+
8406
8433
[[cache-annotations-cacheable-condition]]
8407
8434
===== Conditional caching
8408
8435
Sometimes, a method might not be suitable for caching all the time (for example, it
0 commit comments