Bird
0
0

You have a method that fetches user data from a slow API. You want to cache results but refresh cache every 10 minutes. Which approach best achieves this in Spring Boot?

hard📝 Application Q15 of 15
Spring Boot - Caching
You have a method that fetches user data from a slow API. You want to cache results but refresh cache every 10 minutes. Which approach best achieves this in Spring Boot?
AUse @Cacheable and configure cache manager with 10-minute TTL
BUse @CachePut to update cache on every call
CUse @CacheEvict to clear cache only on application restart
DDo not use caching to avoid stale data
Step-by-Step Solution
Solution:
  1. Step 1: Understand caching with expiration

    To refresh cached data periodically, configure the cache manager with a time-to-live (TTL) setting.
  2. Step 2: Match annotation with cache manager config

    @Cacheable caches method results; TTL in cache manager ensures cache expires after 10 minutes automatically.
  3. Final Answer:

    Use @Cacheable and configure cache manager with 10-minute TTL -> Option A
  4. Quick Check:

    TTL + @Cacheable refreshes cache periodically [OK]
Quick Trick: Set TTL in cache manager with @Cacheable for timed refresh [OK]
Common Mistakes:
  • Using @CachePut causes cache update every call, no TTL
  • Relying on @CacheEvict only on restart misses timed refresh
  • Avoiding caching loses performance benefits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes