Recall & Review
beginner
What is the purpose of the @CacheEvict annotation in Spring Boot?
The @CacheEvict annotation is used to remove or invalidate cache entries when a method is called, ensuring that stale data is not served from the cache.
Click to reveal answer
beginner
How do you specify which cache to evict using @CacheEvict?
You specify the cache name(s) to evict using the 'value' or 'cacheNames' attribute, for example: @CacheEvict(value = "usersCache").
Click to reveal answer
intermediate
What does the 'allEntries' attribute do in @CacheEvict?
Setting 'allEntries = true' removes all entries from the specified cache instead of just the one related to the method's key.
Click to reveal answer
intermediate
Explain the use of 'beforeInvocation' attribute in @CacheEvict.
The 'beforeInvocation' attribute controls whether the cache eviction happens before the method runs (true) or after it completes (false). By default, eviction happens after the method runs.
Click to reveal answer
intermediate
Can @CacheEvict be used to evict multiple caches at once? How?
Yes, by specifying multiple cache names in the 'value' or 'cacheNames' attribute as an array, e.g., @CacheEvict(value = {"cache1", "cache2"}).
Click to reveal answer
What happens if you set allEntries = true in @CacheEvict?
✗ Incorrect
Setting allEntries = true removes all entries from the cache, not just the one related to the method key.
When does cache eviction occur by default with @CacheEvict?
✗ Incorrect
By default, cache eviction happens after the annotated method completes successfully.
How do you specify multiple caches to evict in @CacheEvict?
✗ Incorrect
You can specify multiple caches by passing an array of cache names to the value or cacheNames attribute.
What does setting beforeInvocation = true do in @CacheEvict?
✗ Incorrect
Setting beforeInvocation = true causes cache eviction to happen before the annotated method runs.
Which attribute in @CacheEvict defines the cache to clear?
✗ Incorrect
The value or cacheNames attribute specifies which cache(s) to evict entries from.
Describe how @CacheEvict helps keep cache data fresh in a Spring Boot application.
Think about when and why you want to clear cache entries.
You got /4 concepts.
Explain the difference between evicting cache before vs after method execution using @CacheEvict.
Consider what happens if the method fails or throws an error.
You got /4 concepts.