|
|
@ -261,6 +261,17 @@ needs to be capable of `CompletableFuture`-based retrieval. The Spring-provided |
|
|
|
`CaffeineCacheManager` natively supports it when its asynchronous cache mode is |
|
|
|
`CaffeineCacheManager` natively supports it when its asynchronous cache mode is |
|
|
|
enabled: set `setAsyncCacheMode(true)` on your `CaffeineCacheManager` instance. |
|
|
|
enabled: set `setAsyncCacheMode(true)` on your `CaffeineCacheManager` instance. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
@Bean |
|
|
|
|
|
|
|
CacheManager cacheManager() { |
|
|
|
|
|
|
|
CaffeineCacheManager cacheManager = new CaffeineCacheManager(); |
|
|
|
|
|
|
|
cacheManager.setCacheSpecification(...); |
|
|
|
|
|
|
|
cacheManager.setAsyncCacheMode(true); |
|
|
|
|
|
|
|
return cacheManager; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
Last but not least, be aware that annotation-driven caching is not appropriate |
|
|
|
Last but not least, be aware that annotation-driven caching is not appropriate |
|
|
|
for sophisticated reactive interactions involving composition and back pressure. |
|
|
|
for sophisticated reactive interactions involving composition and back pressure. |
|
|
|
If you choose to declare `@Cacheable` on specific reactive methods, consider the |
|
|
|
If you choose to declare `@Cacheable` on specific reactive methods, consider the |
|
|
@ -489,10 +500,13 @@ Placing this annotation on the class does not turn on any caching operation. |
|
|
|
An operation-level customization always overrides a customization set on `@CacheConfig`. |
|
|
|
An operation-level customization always overrides a customization set on `@CacheConfig`. |
|
|
|
Therefore, this gives three levels of customizations for each cache operation: |
|
|
|
Therefore, this gives three levels of customizations for each cache operation: |
|
|
|
|
|
|
|
|
|
|
|
* Globally configured, available for `CacheManager`, `KeyGenerator`. |
|
|
|
* Globally configured, e.g. through `CachingConfigurer`: see next section. |
|
|
|
* At the class level, using `@CacheConfig`. |
|
|
|
* At the class level, using `@CacheConfig`. |
|
|
|
* At the operation level. |
|
|
|
* At the operation level. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOTE: Provider-specific settings are typically available on the `CacheManager` bean, |
|
|
|
|
|
|
|
e.g. on `CaffeineCacheManager`. These are effectively also global. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[cache-annotation-enable]] |
|
|
|
[[cache-annotation-enable]] |
|
|
|
== Enabling Caching Annotations |
|
|
|
== Enabling Caching Annotations |
|
|
@ -511,6 +525,13 @@ To enable caching annotations add the annotation `@EnableCaching` to one of your |
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@EnableCaching |
|
|
|
@EnableCaching |
|
|
|
public class AppConfig { |
|
|
|
public class AppConfig { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
|
|
|
CacheManager cacheManager() { |
|
|
|
|
|
|
|
CaffeineCacheManager cacheManager = new CaffeineCacheManager(); |
|
|
|
|
|
|
|
cacheManager.setCacheSpecification(...); |
|
|
|
|
|
|
|
return cacheManager; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
@ -526,6 +547,10 @@ Alternatively, for XML configuration you can use the `cache:annotation-driven` e |
|
|
|
http://www.springframework.org/schema/cache https://www.springframework.org/schema/cache/spring-cache.xsd"> |
|
|
|
http://www.springframework.org/schema/cache https://www.springframework.org/schema/cache/spring-cache.xsd"> |
|
|
|
|
|
|
|
|
|
|
|
<cache:annotation-driven/> |
|
|
|
<cache:annotation-driven/> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<bean id="cacheManager" class="org.springframework.cache.caffeine.CaffeineCacheManager"> |
|
|
|
|
|
|
|
<property name="cacheSpecification" value="..."/> |
|
|
|
|
|
|
|
</bean> |
|
|
|
</beans> |
|
|
|
</beans> |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|