Spring Boot & Microservices (50 Qs)•Part 3: Microservices, Distributed Systems & Observability (25 - 35)
Spring Cache with Redis: `@Cacheable`, `@CachePut`, and `@CacheEvict`.
senior LevelMost AskedSystem DesignMicroservices
In Simple Words: Spring Cache provides declarative abstraction over caching layers:
@Cacheable(value = "users", key = "#id"): Returns cached value if present; otherwise runs method and stores result.@CachePut(value = "users", key = "#user.id"): Always executes method and updates the cache.@CacheEvict(value = "users", key = "#id"): Removes entry from cache on delete/update.