-
-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Issue
The lastLoaded timestamp in the LoadableHttpResource class is not persisted to disk along with the cached data. When the VM is restarted, this timestamp is reset to its default value of 0, causing the cache to be considered invalid and triggering unnecessary remote server requests.
Current Behavior
In LoadableHttpResource.java, the load() method checks if the cache is valid using:
if ((lastLoaded + cacheTTLMillis) <= System.currentTimeMillis()) {
clearCache();
}When data is loaded from a remote source, the timestamp is updated:
// In load(URI itemToLoad, boolean fallbackLoad) method
if (!fallbackLoad) {
writeCache();
lastLoaded = System.currentTimeMillis();
loadCount.incrementAndGet();
}However, the writeCache() method only writes the data to disk, not the timestamp:
protected void writeCache() throws IOException {
if (this.cache != null) {
byte[] data = this.data == null ? null : this.data.get();
if (data == null) {
return;
}
this.cache.write(resourceId, data);
}
}This means that on VM restart, lastLoaded is reset to 0, and the condition (lastLoaded + cacheTTLMillis) <= System.currentTimeMillis() will always be true, causing the cache to be considered invalid.
Expected Behavior
The lastLoaded timestamp should be persisted to disk along with the cached data, so that on VM restart, the system can determine if the cache is still valid based on the actual time it was last loaded.