Redis from Spring
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
use Redis through Spring Data Redis and cache annotations.
Planned topics
spring-boot-starter-data-redisconfigures a connection factory;StringRedisTemplatehandles strings.RedisTemplateneeds serializers; prefer JSON over Java serialization.- Enable caching with
@EnableCaching, define aRedisCacheManagerwith per-cache TTL. @Cacheablefills the cache,@CacheEvictremoves entries,@CachePutupdates.- Annotations work through proxies: a self-call inside the same class bypasses the cache.
Draft outline details
Demonstration
@Cacheable(cacheNames = "products", key = "#id")
public ProductDto findProduct(long id) { return repo.load(id); }
RedisCacheConfiguration cfg = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(10)).disableCachingNullValues();Check your understanding
Why might @Cacheable not work on a method called from the same class?
Show answer
The proxy is bypassed.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.