0
0
Spring Bootframework~10 mins

@CacheEvict for invalidation in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to evict the cache named 'books' after the method runs.

Spring Boot
@CacheEvict(cacheNames = "[1]")
public void clearCache() {
    // method body
}
Drag options to blanks, or click blank then click option'
Ausers
Bproducts
Corders
Dbooks
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong cache name that does not exist.
Forgetting to specify the cache name.
2fill in blank
medium

Complete the code to evict all entries in the 'books' cache after the method runs.

Spring Boot
@CacheEvict(cacheNames = "books", [1] = true)
public void clearAllBooksCache() {
    // method body
}
Drag options to blanks, or click blank then click option'
AallEntries
Bkey
Ccondition
DbeforeInvocation
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'key' instead of 'allEntries' to clear all cache entries.
Not setting the attribute to true.
3fill in blank
hard

Fix the error in the code to evict the cache entry with key '123' from the 'books' cache.

Spring Boot
@CacheEvict(cacheNames = "books", key = "[1]")
public void evictBook() {
    // method body
}
Drag options to blanks, or click blank then click option'
A123
B'123'
C"123"
Dkey
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number without quotes as key.
Using double quotes inside double quotes without escaping.
4fill in blank
hard

Fill both blanks to evict the cache entry with key 'id' before the method runs.

Spring Boot
@CacheEvict(cacheNames = "books", key = "[1]", [2] = true)
public void evictBefore(Long id) {
    // method body
}
Drag options to blanks, or click blank then click option'
A#id
Bfalse
CbeforeInvocation
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the parameter name without '#' in key.
Not setting beforeInvocation to true.
5fill in blank
hard

Fill all three blanks to evict the cache entry with key 'user.id' only if the user's status is 'inactive'.

Spring Boot
@CacheEvict(cacheNames = "users", key = "[1]", condition = "[2] == 'inactive'", [3] = false)
public void evictInactiveUser(User user) {
    // method body
}
Drag options to blanks, or click blank then click option'
A#user.id
B#user.status
CbeforeInvocation
DallEntries
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong SpEL expressions for key or condition.
Confusing beforeInvocation with allEntries.