Yes, you can simply call load()
:
private void onTimer() {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
load(); // Call the containing class method
}
}, TTL * 60000);
}
because every anonymous class is actually also an inner class, so it has a reference to the containing class that declares it.
But, you would only use a Timer if you really wanted active expiration. You already have lazy expiration due to the call to verifyCache()
in every call to get()
. Maybe that's enough for your needs now.