Thanks @ben.manes, I got past the exception, but now it looks like it's adding to the cache but I do not find the key in the cache when I fetch the key. This is how I have initialized the cache, I assume this happens only once? or everytime you do a .put into the cache object?
private static final Cache<String,MyToken> tokenCache = AccessController.doPrivileged((PrivilegedAction<Cache<String,MyToken>>) () -> {
final com.github.benmanes.caffeine.cache.Cache<String, MyToken> cache = Caffeine.newBuilder().expireAfter(new Expiry<String, MyToken>() {
@Override
public long expireAfterCreate(
String key, MyToken value, long currentTime) {
// This is for testing
return 300000;
}
@Override
public long expireAfterUpdate(
String key, MyToken value, long currentTime, long currentDuration) {
return currentDuration;
}
@Override
public long expireAfterRead(
String key, MyToken value, long currentTime, long currentDuration) {
return currentDuration;
}
}).executor(Runnable::run).build();
return cache;
});