Spring provides two ways to evict a cache, either by using the @CacheEvict annotation on a method, or by auto-wiring the CacheManger and clearing it by calling the clear() method.
Cache eviction is a feature where file data blocks in the cache are released when fileset usage exceeds the fileset soft quota, and space is created for new files. The process of releasing blocks is called eviction. However, file data is not evicted if the file data is dirty.
This allows for customizing the strategy for cache key generation, per Spring's KeyGenerator SPI. Normally, @EnableCaching will configure Spring's SimpleKeyGenerator for this purpose, but when implementing CachingConfigurer , a key generator must be provided explicitly.
You can do this:
@Caching(evict = {
@CacheEvict("primary"),
@CacheEvict(value = "secondary", key = "#p0")
})
Check out the Reference for details
Keep it compact: You can evict multiple caches by enumerating them inside the @CacheEvict
annotation:
@CacheEvict(value = { "cache1", "cache2" }, allEntries = true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With