Bird
0
0

You want to cache only orders with amount greater than 500 in Redis using Spring Boot caching. Which approach correctly implements this?

hard📝 Application Q8 of 15
Spring Boot - Caching
You want to cache only orders with amount greater than 500 in Redis using Spring Boot caching. Which approach correctly implements this?
AConfigure Redis to filter cached entries by amount automatically
BUse @CachePut and manually check amount inside method
CUse @CacheEvict to remove orders with amount <= 500 after caching
DUse @Cacheable with a condition: @Cacheable(value = "orders", condition = "#order.amount > 500")
Step-by-Step Solution
Solution:
  1. Step 1: Use condition attribute

    @Cacheable supports SpEL condition to cache selectively.
  2. Step 2: Apply condition for amount

    Setting condition = "#order.amount > 500" caches only qualifying orders.
  3. Step 3: Evaluate other options

    @CachePut updates cache but doesn't filter; @CacheEvict removes entries after caching; Redis itself doesn't filter cache entries automatically.
  4. Final Answer:

    Use @Cacheable with a condition: @Cacheable(value = "orders", condition = "#order.amount > 500") -> Option D
  5. Quick Check:

    Use condition in @Cacheable to filter cache [OK]
Quick Trick: Use @Cacheable condition to cache selectively [OK]
Common Mistakes:
  • Trying to filter cache entries inside Redis config
  • Using @CachePut without condition
  • Relying on @CacheEvict to filter cache

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes