Skip to content

reload immediately on expiry #517

Answered by ben-manes
koushikroy1989 asked this question in Q&A
Discussion options

You must be logged in to vote

The Scheduler can be used in Java 8, but you will have to supply your own thread. For example,

Scheduler scheduler = Scheduler.forScheduledExecutorService(es);
return Caffeine.newBuilder()
    .scheduler(scheduler)
    .expireAfter(...)
    .removalListener((key, value, cause) -> {
      if (cause == RemovalCause.EXPIRED) {
        load(key);
      }
    }).build();

In Java 9 introduced a global scheduler thread to avoid many ad hoc ones, which we expose through Scheduler.systemScheduler(). Since the 2.x release is Java 8 based, in that JVM the method falls back to returning Scheduler.disabledScheduler(). This just means you need to create and manage the lifecycle of a ScheduledExecutorSe…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@koushikroy1989
Comment options

@ben-manes
Comment options

@koushikroy1989
Comment options

@ben-manes
Comment options

@krishna81m
Comment options

Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants