@Retention(value=RUNTIME) @Target(value=METHOD) public @interface CacheResult
CacheResult
is invoked, Quarkus will compute a cache key and use it to check in the
cache whether the method has been already invoked. If the method has one or more arguments, the key computation is done from
all the method arguments if none of them is annotated with CacheKey
, or all the arguments annotated with
CacheKey
otherwise. This annotation can also be used on a method with no arguments, a default key derived from the
cache name is generated in that case. If a value is found in the cache, it is returned and the annotated method is never
actually executed. If no value is found, the annotated method is invoked and the returned value is stored in the cache using
the computed or generated key.
A method annotated with CacheResult
is protected by a lock on cache miss mechanism. If several concurrent
invocations try to retrieve a cache value from the same missing key, the method will only be invoked once. The first
concurrent invocation will trigger the method invocation while the subsequent concurrent invocations will wait for the end
of the method invocation to get the cached result. The lockTimeout
parameter can be used to interrupt the lock after
a given delay. The lock timeout is disabled by default, meaning the lock is never interrupted. See the parameter Javadoc for
more details.
This annotation cannot be used on a method returning void
.
You can only use one of the cache operations (and this annotation) on a given method: CacheResult
,
CacheInvalidate
or CacheInvalidateAll
.
The underlying caching provider can be chosen and configured in the Quarkus application.properties
file.
Modifier and Type | Required Element and Description |
---|---|
String |
cacheName
The name of the cache.
|
Modifier and Type | Optional Element and Description |
---|---|
long |
lockTimeout
Delay in milliseconds before the lock on cache miss is interrupted.
|
public abstract String cacheName
public abstract long lockTimeout
0
(which is the default one) means
that the lock timeout is disabled.Copyright © 2020 JBoss by Red Hat. All rights reserved.