Applying Spring Cache
This final recipe will be about enhancing data retrieval from the data source through Spring Cache. Just like the rest of the recipes, Spring Boot 2.0 provides an auto-configuration when it comes to caching. It supports cache implementations such as Ehcache
, Infinispan
, Caffeine
, Hazelcast
, and Redis
. The following is a recipe on how to use two caching types in one reactive application.
Getting started
Open, for the last time, ch09-flux
and enable Ehcache
and Caffeine
caching.
How to do it...
To enable Spring Cache in Spring Boot 2.0 application, follow these steps:
- Add the starter POM for Spring Boot 2.0 caching:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency>
- For
Ehcache
auto-configuration, add the followingEhcache
provider to the Maven dependencies:
<dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache<...