Neither expireAfterWrite, nor expireAfterAccess work when using this extension.
What really happens is that expired entry is going through removal process in Guava cache, but instead of being deleted it gets persisted on disk and loaded to cache like brand new item right there.
Fill cache with some values.
cache.put("apple", "fresh");
wait 10+ sec.
Get the entry you expect to expire.
String res = cache.get("apple");
ExpRes - res is null as well as entry for apple is expired.
AchRes - res is "fresh", because it was not removed from cache but stored on disk and then loaded back.
Neither expireAfterWrite, nor expireAfterAccess work when using this extension. What really happens is that expired entry is going through removal process in Guava cache, but instead of being deleted it gets persisted on disk and loaded to cache like brand new item right there.
It's actually happening because of these lines:
protected boolean isPersistenceRelevant(RemovalCause removalCause) { return removalCause != RemovalCause.EXPLICIT && removalCause != RemovalCause.REPLACED; }
So RemovalCause.EXPIRED is treated as relevant cause for persistence.
To reproduce the issue:
Cache<String, String> c = FileSystemCacheBuilder.newBuilder() .maximumSize(100000) .expireAfterWrite(10000, TimeUnit.MILLISECONDS) .persistenceDirectory(new File(persistenceDirectory)) .recordStats() .build();
cache.put("apple", "fresh");
String res = cache.get("apple");
ExpRes - res is null as well as entry for apple is expired. AchRes - res is "fresh", because it was not removed from cache but stored on disk and then loaded back.