Bird
0
0

Consider this method annotated with @CachePut:

medium📝 Debug Q14 of 15
Spring Boot - Caching
Consider this method annotated with @CachePut:
@CachePut(value = "orders", key = "#order.id")
public Order updateOrder(Order order) {
    // missing return statement
}
What is the problem with this code?
AThe method should be annotated with @Cacheable instead
BThe key expression is invalid and causes a syntax error
CThe cache name 'orders' is not allowed in @CachePut
DThe method does not return a value, so cache cannot be updated
Step-by-Step Solution
Solution:
  1. Step 1: Check method return requirement for @CachePut

    @CachePut requires the method to return a value to update the cache with that value.
  2. Step 2: Identify missing return statement issue

    The method lacks a return statement, so no value is returned to update the cache, causing runtime issues.
  3. Final Answer:

    The method does not return a value, so cache cannot be updated -> Option D
  4. Quick Check:

    @CachePut needs method return to update cache [OK]
Quick Trick: Always return updated value when using @CachePut [OK]
Common Mistakes:
  • Forgetting to return the updated object
  • Confusing cache name attribute
  • Using @Cacheable instead of @CachePut incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes