October 2017
Intermediate to advanced
396 pages
10h 2m
English
Spring's cache abstraction not only allows populating caches, but also allows removing the cached data from the cache. There is a stage in the application where you have to remove stale or unused data from the cache. In that case, you can use the @CacheEvict annotation, because it doesn't add anything to the cache unlike the @Cacheable annotation. The @CacheEvict annotation is used only to perform cache eviction. Let's see how this annotation makes the remove() method of AccountRepository as a cache eviction:
@CacheEvict("accountCache ")
void remove(Long accountId);
As you can see in the preceding code snippet, the value associated with the argument, accountId, is removed from the accountCache cache when the ...
Read now
Unlock full access