Each time an advised method is invoked, caching behavior will be applied,
checking whether the method has been already invoked for the given arguments.
A sensible default simply uses the method parameters to compute the key, but
a SpEL expression can be provided via the key attribute, or a custom
org. implementation can
replace the default one (see keyGenerator).
If no value is found in the cache for the computed key, the target method
will be invoked and the returned value will be stored in the associated cache.
Note that java. return types are unwrapped automatically.
If an Optional value is present, it will be stored in the associated cache. If an Optional
value is not present, null will be stored in the associated cache.
This annotation may be used as a meta-annotation to create custom composed annotations with attribute overrides.
CacheConfig
| Modifier and Type | Method and Description |
|---|---|
| public String | cacheManager()
The bean name of the custom |
| public String[] | |
| public String | cacheResolver()
The bean name of the custom |
| public String | condition()
Spring Expression Language (SpEL) expression used for making the method caching conditional. |
| public String | |
| public String | keyGenerator()
The bean name of the custom |
| public boolean | sync()
Synchronize the invocation of the underlying method if several threads are attempting to load a value for the same key. |
| public String | |
| public String[] |
| cacheManager | back to summary |
|---|---|
| public String cacheManager() The bean name of the custom Mutually exclusive with the | |
| cacheNames | back to summary |
|---|---|
| public String[] cacheNames() Names of the caches in which method invocation results are stored. Names may be used to determine the target cache(s), to be resolved via the
configured This will usually be a single cache name. If multiple names are specified, they will be consulted for a cache hit in the order of definition, and they will all receive a put/evict request for the same newly cached value. Note that asynchronous/reactive cache access may not fully consult all specified caches, depending on the target cache. In the case of late-determined cache misses (e.g. with Redis), further caches will not get consulted anymore. As a consequence, specifying multiple cache names in an async cache mode setup only makes sense with early-determined cache misses (e.g. with Caffeine).
| |
| cacheResolver | back to summary |
|---|---|
| public String cacheResolver() The bean name of the custom
| |
| condition | back to summary |
|---|---|
| public String condition() Spring Expression Language (SpEL) expression used for making the method
caching conditional. Cache the result if the condition evaluates to
Default is The SpEL expression evaluates against a dedicated context that provides the following meta-data:
| |
| key | back to summary |
|---|---|
| public String key() Spring Expression Language (SpEL) expression for computing the key dynamically. Default is The SpEL expression evaluates against a dedicated context that provides the following meta-data:
| |
| keyGenerator | back to summary |
|---|---|
| public String keyGenerator() The bean name of the custom Mutually exclusive with the
| |
| sync | back to summary |
|---|---|
| public boolean sync() Synchronize the invocation of the underlying method if several threads are attempting to load a value for the same key. The synchronization leads to a couple of limitations:
| |
| unless | back to summary |
|---|---|
| public String unless() Spring Expression Language (SpEL) expression used to veto method caching.
Veto caching the result if the condition evaluates to Unlike Default is The SpEL expression evaluates against a dedicated context that provides the following meta-data:
| |
| value | back to summary |
|---|---|
| public String[] value() Alias for
| |