Bird
0
0

Why might you use @CacheEvict(allEntries = true, beforeInvocation = true) together?

hard📝 Conceptual Q10 of 15
Spring Boot - Caching
Why might you use @CacheEvict(allEntries = true, beforeInvocation = true) together?
ATo clear all cache entries before method runs, ensuring fresh data even if method fails
BTo clear cache entries only if method completes successfully
CTo evict only one cache entry before method runs
DTo disable caching for the method
Step-by-Step Solution
Solution:
  1. Step 1: Understand allEntries and beforeInvocation

    allEntries=true clears all cache entries; beforeInvocation=true evicts before method execution.
  2. Step 2: Reason about failure scenarios

    Evicting before method runs ensures cache is cleared even if method throws an exception.
  3. Final Answer:

    To clear all cache entries before method runs, ensuring fresh data even if method fails -> Option A
  4. Quick Check:

    Evict all before method to avoid stale cache on failure [OK]
Quick Trick: Use beforeInvocation to evict cache before method runs [OK]
Common Mistakes:
  • Thinking eviction happens only after method success
  • Confusing beforeInvocation with condition
  • Assuming it disables caching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes