0

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?

  • I think you can find answer here: https://stackoverflow.com/questions/74130063/is-there-anyway-to-refresh-the-caffeine-cache-on-certain-interval-wihtout-adding Or here: https://stackoverflow.com/questions/57886754/how-to-update-cache-every-30-minutes-in-spring – Axiomatic-1 Aug 25 '23 at 11:38

0 Answers0