Skip to content

Commit bcfc09a

Browse files
committed
Document sync attribute of Cacheable
Closes gh-14366
1 parent b92576d commit bcfc09a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/asciidoc/integration.adoc

+27
Original file line numberDiff line numberDiff line change
@@ -8403,6 +8403,33 @@ result in an exception as a custom `CacheManager` will be ignored by the
84038403
`CacheResolver` implementation. This is probably not what you expect.
84048404
====
84058405

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+
84068433
[[cache-annotations-cacheable-condition]]
84078434
===== Conditional caching
84088435
Sometimes, a method might not be suitable for caching all the time (for example, it

0 commit comments

Comments
 (0)