Explain how you would use Redis for caching in a Spring Boot app. How would you invalidate stale cache?
TechnicalTech lead javaJava Tech LeadSoftware EngineerBackend DeveloperTo use Redis for caching in a Spring Boot app, I would integrate it with the Spring Cache abstraction. This allows me to annotate methods with @Cacheable to store results in Redis, improving performance by reducing database calls.
For invalidating stale cache, I would utilize @CacheEvict to clear the cache when data is updated. Additionally, I can set a time-to-live for cache entries, ensuring they expire after a certain period, which helps maintain data consistency.