redisson +spring caching

https://github.com/redisson/redisson/wiki/14.-Integration%20with%20frameworks#142-spring-cache

https://howtodoinjava.com/spring-boot2/spring-boot-cache-example/

cache providers

CacheManager
Spring provides one concurrent hashmap as default cache, but we can override CacheManager to register external cache providers as well easily.

cache usages

@CacheConfig
 — you can define some of the cache configuration in one place — at the class level — so that you won’t need to declare stuff several times.

@CacheConfig(cacheNames={"users"}) // tells Spring where to store cache for this class

@Cacheable — when method annotated with this annotation, it will be executed only once for the given cachekey, until the cache expires or gets cleared.

@Cacheable method cache execute process

— first time it will take those 3 with something seconds to get data back to you. Because firstly it will check the cache, and will see that it is empty, and will execute the method, with 3 seconds delay. But all further requests to findAll() will be executed much much faster, because method will not be executed, since requested data was cached previously and will be taken for you from the cache.
@Cacheable
首先检测缓存数据, 有缓存则直接用缓存(不执行方法), 否则执行方法获取缓存。

你可能感兴趣的:(redisson +spring caching)