Bird
0
0

Identify the error in this cache configuration snippet:

medium📝 Debug Q6 of 15
Spring Boot - Caching
Identify the error in this cache configuration snippet:
@Cacheable(cacheName = "products")
public Product getProduct(int id) {
  return productRepo.findById(id);
}
AMethod must return void to use caching
BThe attribute should be 'value' not 'cacheName'
CCacheable annotation requires a key attribute
DThe method parameter must be a String
Step-by-Step Solution
Solution:
  1. Step 1: Check @Cacheable attribute names

    The correct attribute to specify cache names is value, not cacheName.
  2. Step 2: Validate other options

    Method can return any type; key is optional; parameter type can vary.
  3. Final Answer:

    The attribute should be 'value' not 'cacheName' -> Option B
  4. Quick Check:

    @Cacheable uses 'value' for cache names [OK]
Quick Trick: Use 'value' attribute in @Cacheable, not 'cacheName' [OK]
Common Mistakes:
  • Using 'cacheName' instead of 'value'
  • Thinking key attribute is mandatory
  • Assuming method return type restrictions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes