Bird
0
0

Why does @CachePut update the cache even if the cached value already exists, unlike @Cacheable?

hard📝 Conceptual Q10 of 15
Spring Boot - Caching
Why does @CachePut update the cache even if the cached value already exists, unlike @Cacheable?
A@CachePut only caches null return values.
B@CachePut skips method execution if cache exists.
C@CachePut always executes the method and updates cache to keep data fresh.
D@CachePut clears the cache before method execution.
Step-by-Step Solution
Solution:
  1. Step 1: Compare @CachePut and @Cacheable behavior

    @Cacheable caches method result only if absent, skipping method execution if cached. @CachePut always runs method and updates cache.
  2. Step 2: Understand why @CachePut updates cache every time

    This ensures cache stays fresh with latest data after method runs, unlike @Cacheable which may serve stale data.
  3. Final Answer:

    @CachePut always executes the method and updates cache to keep data fresh. -> Option C
  4. Quick Check:

    @CachePut refreshes cache by always running method [OK]
Quick Trick: @CachePut runs method always to refresh cache [OK]
Common Mistakes:
  • Thinking @CachePut skips method if cached
  • Believing @CachePut caches only null returns
  • Assuming @CachePut clears cache before method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes