Bird
0
0

What is wrong with this usage?

medium📝 Debug Q6 of 15
Spring Boot - Caching
What is wrong with this usage?
@CacheEvict(cacheNames = "products", key = "id")
public void evictProduct(Long id) { /* logic */ }
AMethod must return a value to use @CacheEvict
BThe key expression should be '#id' to reference the method parameter
CcacheNames should be 'product' not 'products'
DThe annotation must be placed on a class, not a method
Step-by-Step Solution
Solution:
  1. Step 1: Check key expression syntax

    The key must use SpEL with '#' to reference parameters, so it should be '#id'.
  2. Step 2: Validate other attributes

    cacheNames can be any valid cache name; method return type and annotation placement are correct.
  3. Final Answer:

    The key expression should be '#id' to reference the method parameter -> Option B
  4. Quick Check:

    Key must use # for parameter reference [OK]
Quick Trick: Always prefix key with # for method parameters [OK]
Common Mistakes:
  • Omitting # in key expression
  • Assuming cacheNames must match method name
  • Thinking @CacheEvict requires return value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes