Bird
0
0

You want to configure a cache in Spring Boot that stores user data and expires entries after 10 minutes. Which approach correctly combines cache configuration and expiration?

hard📝 Application Q15 of 15
Spring Boot - Caching
You want to configure a cache in Spring Boot that stores user data and expires entries after 10 minutes. Which approach correctly combines cache configuration and expiration?
AUse @EnableCaching and define a ConcurrentMapCacheManager bean with TTL set to 10 minutes
BUse @CachePut and manually remove cache entries after 10 minutes
CUse @EnableCaching and configure a CaffeineCacheManager with expiry policy of 10 minutes
DUse @Cacheable with a parameter to set expiration time to 10 minutes
Step-by-Step Solution
Solution:
  1. Step 1: Understand cache expiration support

    ConcurrentMapCacheManager does not support TTL (time to live) expiration by default.
  2. Step 2: Identify cache manager with TTL support

    CaffeineCacheManager supports expiration policies like 10-minute TTL.
  3. Step 3: Evaluate options

    @Cacheable does not accept expiration parameters; @CachePut updates cache but does not manage expiration automatically.
  4. Final Answer:

    Use @EnableCaching and configure a CaffeineCacheManager with expiry policy of 10 minutes -> Option C
  5. Quick Check:

    CaffeineCacheManager supports TTL expiration [OK]
Quick Trick: Use CaffeineCacheManager for TTL expiration [OK]
Common Mistakes:
  • Assuming ConcurrentMapCacheManager supports TTL
  • Trying to set expiration via @Cacheable annotation
  • Using @CachePut to handle expiration manually

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes