0
0
Spring Bootframework~5 mins

@CacheEvict for invalidation in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AAll entries in the specified cache are removed
BThe cache entries are refreshed automatically
CThe cache is disabled permanently
DOnly the cache entry related to the method key is removed
When does cache eviction occur by default with @CacheEvict?
ABefore the annotated method runs
BOnly if the method throws an exception
CAfter the annotated method completes successfully
DImmediately when the application starts
How do you specify multiple caches to evict in @CacheEvict?
AYou cannot evict multiple caches at once
BUse multiple @CacheEvict annotations
CUse the cacheNames attribute with a single string
DPass an array of cache names to the value attribute
What does setting beforeInvocation = true do in @CacheEvict?
AEvicts cache entries before the method runs
BEvicts cache entries after the method runs
CPrevents cache eviction
DEvicts cache only if the method throws an exception
Which attribute in @CacheEvict defines the cache to clear?
Akey
Bvalue or cacheNames
Ccondition
Dsync
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.