Skip to content
Ameen Abozaid
Planned lessonMID-038-L07

Demo: caching product details with @Cacheable

  • Lesson 7 of 7
  • Mid-level
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

  1. Add the Redis starter and a RedisCacheManager with a 10-minute TTL for products.
  2. Annotate findProduct with @Cacheable and the update method with @CacheEvict.
  3. Enable cache statistics and read hits/misses in Micrometer (verify the metric names for your Spring Boot version).
  4. Run a load test; compare latency with and without the cache.
  5. Planned mistake: cache a Product entity that is not Serializable and uses Java serialization; it fails or breaks on a class change. Fix: cache a small DTO with JSON serialization.
  6. 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.