'Spring cache and Spring data redis

  1. Spring cache + Spring redis: Spring provides a caching abstraction package spring-boot-starter-cache which basically provides method level annotations to cache data with @Cacheable, @Cacheput and other annotations. I feel there are limitations to this: Caching a collection of POJO against a property (for example: Person.getId() as the key from List<Person> as a return type). And the other limitation is searching. How do I query and search data in the cache provider?

  2. Spring redis: Then there is spring-boot-starter-data-redis which basically contains: spring-data-redis and lettuce. 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