I'm trying to use caffeine and spring-boot-starter-cache to implement the following caching logic:
- If expiration time has passed and condition (That requires computation and I/O) is evaluated to TRUE then force fetch the data and update cache.
- If expiration time has passed and condition (That requires computation and I/O) is evaluated to FALSE then don't invalidate the cache data and retrieve the value from cache.
- If expiration time has not passed then retrieve the value from cache.
I worked according to this guide: https://www.baeldung.com/spring-boot-caffeine-cache
I tried all sort of approaches using @CachePut, @CacheEvict and @Cacheable on the getter method of the object I;m caching but the core issue is that I need to condition the eviction with both an expiration time and another logic but these annotations cannot control whether to evict or not... Perhaps this can be done using a Scheduler?