Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schedule Spring cache eviction?

Tags:

Is it possible to schedule spring cache eviction to everyday at midnight?

I've read Springs Cache Docs and found nothing about scheduled cache eviction.

I need to evict cache daily and recache it in case there were some changes outside my application.

like image 216
Philippe Gioseffi Avatar asked Mar 09 '17 06:03

Philippe Gioseffi


People also ask

How do I evict a spring cache?

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.

What is evicting cache?

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.


1 Answers

Try to use @Scheduled Example:

@Scheduled(fixedRate = ONE_DAY) @CacheEvict(value = { CACHE_NAME }) public void clearCache() {       log.debug("Cache '{}' cleared.", CACHE);     } 

You can also use cron expression with @Scheduled.

like image 157
Oleksandr Bondarchuk Avatar answered Oct 13 '22 03:10

Oleksandr Bondarchuk