'Spring cache and Spring data redis
Spring cache + Spring redis: Spring provides a caching abstraction package
spring-boot-starter-cachewhich basically provides method level annotations to cache data with@Cacheable,@Cacheputand other annotations. I feel there are limitations to this: Caching a collection of POJO against a property (for example:Person.getId()as the key fromList<Person>as a return type). And the other limitation is searching. How do I query and search data in the cache provider?Spring redis: Then there is
spring-boot-starter-data-rediswhich basically contains:spring-data-redisandlettuce. Just using this package without a combination of Spring's Cache means that there has to be some kind of IoC introduced to switch between Database communication and Cache provider. But ofc, directly using redis has advantages in the sense of having better control is storage/retrieval/search/evict.
Which one to choose?
If #1 is chosen, how to gain more control over the caching mechanism (inserting collection/search)?
If #2 is chosen, should the IoC be provided on the service layer like: API -> DB-Service/Cache-Service -> Repo. Or a new layer, like: API -> Optional-Cache-Service -> DB-Service -> Repo
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
