Bird
0
0

Which of the following is the correct syntax to use @CachePut to update a cache named "users" with a key based on the method parameter id?

easy📝 Syntax Q12 of 15
Spring Boot - Caching
Which of the following is the correct syntax to use @CachePut to update a cache named "users" with a key based on the method parameter id?
A@CachePut(cacheName = "users", key = "id")
B@CachePut(value = "users", key = "#id")
C@CachePut(name = "users", key = "id")
D@CachePut(cache = "users", key = "#id")
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct attribute names for @CachePut

    The correct attribute for cache name is 'value' or 'cacheNames', and SpEL expressions for keys use '#'.
  2. Step 2: Analyze each option's syntax

    @CachePut(value = "users", key = "#id") uses 'value' and '#id' correctly. Others use incorrect attribute names or miss the '#' for SpEL.
  3. Final Answer:

    @CachePut(value = "users", key = "#id") -> Option B
  4. Quick Check:

    Use 'value' and '#param' for key in @CachePut [OK]
Quick Trick: Use 'value' for cache name and '#' before param in key [OK]
Common Mistakes:
  • Using wrong attribute names like cacheName or cache
  • Missing '#' in key expression
  • Using plain string instead of SpEL for key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes