Spring - Caching

springmvc

https://spring.io/guides/gs/caching/
https://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html
http://www.baeldung.com/spring-cache-tutorial
https://www.mkyong.com/spring/spring-caching-and-ehcache-example/
http://javabeat.net/spring-cache/
http://websystique.com/spring/spring-4-cacheable-cacheput-cacheevict-caching-cacheconfig-enablecaching-tutorial/
http://www.javacreed.com/caching-made-easy-with-spring/

How can we implement caching with Spring?

Enabling caching in Spring is all the matter of making the right annotation available in appropriate methods. First, we need to enable caching. This is done before using Annotation or XML based configuration.

@Configuration
@EnableCaching
public class AppConfig {
}

The next step is to add the annotation on the method we would like to cache results from:

@Cacheable("players")
public Player findPlayer(int playerId) {
}

Spring offer features to control caching

  1. Conditional Caching: condition="#name.length < 32"
  2. @CachePut: Update existing cache.
  3. @CacheEvict: Remove from cache. For example, the player is deleted.

ehcache.EhCacheCacheManager

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License