Demo: caching product details with @Cacheable
On This Lesson 3 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
cache product details in Redis with a TTL and metrics. Prepares MID-038-LAB1.
Draft outline details
Step by step
- Add the Redis starter and a
RedisCacheManagerwith a 10-minute TTL forproducts. - Annotate
findProductwith@Cacheableand the update method with@CacheEvict. - Enable cache statistics and read hits/misses in Micrometer (verify the metric names for your Spring Boot version).
- Run a load test; compare latency with and without the cache.
- Planned mistake: cache a
Productentity that is notSerializableand uses Java serialization; it fails or breaks on a class change. Fix: cache a small DTO with JSON serialization. - Show the keys with
SCAN 0 MATCH products::*.
Check your understanding
Which operation removes a stale product when its price changes?
Show answer
@CacheEvict, or event-based invalidation in MID-039.
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.