Bird
0
0

Given this code snippet with @EnableCaching and a @Cacheable method, what happens on the second call to getData()?

medium📝 component behavior Q4 of 15
Spring Boot - Caching
Given this code snippet with @EnableCaching and a @Cacheable method, what happens on the second call to getData()?
AThe cached value is returned without executing the method
BThe method executes again and returns a new value
CAn error occurs because caching is not configured
DThe cache is cleared before returning the value
Step-by-Step Solution
Solution:
  1. Step 1: Understand @EnableCaching and @Cacheable interaction

    @EnableCaching activates caching; @Cacheable caches method results on first call.
  2. Step 2: Behavior on second call

    On second call, cached value is returned directly without method execution.
  3. Final Answer:

    The cached value is returned without executing the method -> Option A
  4. Quick Check:

    Second call returns cached result [OK]
Quick Trick: Second call returns cached data, no method run [OK]
Common Mistakes:
  • Assuming method runs every time
  • Expecting cache to clear automatically
  • Thinking caching causes errors without config

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes