Bird
0
0

Given the method annotated as @Cacheable(value = "products", key = "#id") and called with getProduct(5), what will be the cache key used?

medium📝 component behavior Q4 of 15
Spring Boot - Caching
Given the method annotated as @Cacheable(value = "products", key = "#id") and called with getProduct(5), what will be the cache key used?
AgetProduct
B"#id"
Cproducts
D5
Step-by-Step Solution
Solution:
  1. Step 1: Understand key expression evaluation

    The key '#id' evaluates to the method parameter value, which is 5 in this call.
  2. Step 2: Differentiate from string literals

    "#id" as a string literal would not be used; the actual value 5 is the key.
  3. Final Answer:

    5 -> Option D
  4. Quick Check:

    Cache key = parameter value [OK]
Quick Trick: Cache key evaluates SpEL to parameter value [OK]
Common Mistakes:
  • Using the string '#id' as key instead of value
  • Confusing cache name with key
  • Using method name as key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes