Spring Caching with Guava
In Spring core, it also provides Guava Cache support.
Enable Caching
Add
@EnableCaching(mode=AdviceMode.ASPECTJ)
annotation on the configuration class if you are using Java based configuration.@Configuration ... @EnableCaching(mode=AdviceMode.ASPECTJ) public class JpaConfig {...}
Then, specify a
CacheManager
provider in your configuration. There is a GuavaCacheManager
provided by Spring.@Override @Bean public CacheManager cacheManager() { return new GuavaCacheManager(); } @Override @Bean public KeyGenerator keyGenerator() { return new SimpleKeyGenerator(); }
Do not forget to add the guava dependency in your Maven pom.xml file.
<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency>
Code sample
Check out the sample codes.
And explore the spring-cache-guava folder.
评论