Bird
0
0

Given this method annotated with @CachePut:

medium📝 component behavior Q5 of 15
Spring Boot - Caching
Given this method annotated with @CachePut:
@CachePut(value = "sessions", key = "#session.id")
public Session refreshSession(Session session) {
    session.setActive(true);
    return session;
}
What happens if refreshSession is called multiple times with the same session object?
AThe cache entry for that session ID is updated each time with the latest session object.
BThe cache is updated only the first time; subsequent calls do not affect the cache.
CThe cache entry is removed after the first call.
DAn exception is thrown because the cache key is reused.
Step-by-Step Solution
Solution:
  1. Step 1: Understand @CachePut behavior

    @CachePut updates the cache entry every time the method is called, regardless of existing cache content.
  2. Step 2: Analyze repeated calls

    Calling with the same key updates the cache with the new return value each time.
  3. Final Answer:

    The cache entry for that session ID is updated each time with the latest session object. -> Option A
  4. Quick Check:

    @CachePut always refreshes cache entry [OK]
Quick Trick: Cache updates on every method call [OK]
Common Mistakes:
  • Assuming cache updates only once
  • Thinking cache entry is removed
  • Believing key reuse causes errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes