Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CacheEntity<K,V> execute(CacheEntity<K,V> cacheEntity, Action action) {
long now = System.currentTimeMillis();
if(cacheEntity==null) {
return null;
}
if(cacheEntity.isExpired()) {
storage.remove(cacheEntity);
return null;
}
Duration duration;
switch (action) {
case CHECK:
return cacheEntity;
/*
* This method is called by a caching implementation after a Cache.Entry is
* created, but before a Cache.Entry is added to a cache
*/
case CREATE:
duration = policy.getExpiryForCreation();
break;
/*
* This method is called by a caching implementation after a Cache.Entry is
* accessed to determine the {@link Duration} before an entry expires.
*/
case ACCESS:
duration = policy.getExpiryForAccess();
break;
/*
* This method is called by the caching implementation after a Cache.Entry is
* updated to determine the {@link Duration} before the updated entry expires.
*/
case UPDATE:
duration = policy.getExpiryForUpdate();
break;
default:
return cacheEntity;
}
if(duration==null) {
return cacheEntity;
}
if(duration.isZero()) {
storage.remove(cacheEntity);
return null;
}
long expireTime = duration.getAdjustedTime(now);
cacheEntity.setExpireTimestamp(expireTime);
if(cacheEntity.isExpired()) {
storage.remove(cacheEntity);
return null;
}
return cacheEntity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.