I have a requirement in which it is required to invalidate or cleanup a cache every day around the fixed time. I can schedule a daily job to invalidate the cache at the fixed time. However, I am not looking for that.
Is there any other simpler approach to invalidate the cache like some in-built methods or are there any other suggestions?
You can use expireAfterAccess
.
It specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation
expireAfterAccess(long duration, TimeUnit unit)
If you want to invalidate at specified time, you can create a schedular thread that runs at specific time and calls invalidateAll()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.