I have currently this code for Caffeine cache(I want to have all rules from DB in my cache, since there is no lot of them):
public class CaffeineCache {
LoadingCache<String, Rule> cache = Caffeine.newBuilder()
.maximumSize(10_000)
.build(key -> Rule.builder().build());
public Collection<Rule> getRules() {
return cache.asMap().values();
}
public void addRule(Rule rule) {
cache.put(rule.getRuleId(), rule);
}
public void refreshCache() {
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(
() -> cache.refresh("SOME_KEY"),
0, 15, TimeUnit.MINUTES
);
}
I want to update my cache every 15 minutes(no matter if there are new values or not). If it not correct approach, what should I do?