Skip to content

Cache invalidation on VM restart due to non-persisted lastLoaded timestamp #434

Description

@infernap12

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.

Activity

  1. infernap12 commented on May 18, 2025

    @infernap12
    Author

    Willing to investigate an avenue for remediating this, but didn't want to pursue an avenue that would be unacceptable.

    Would updating the ResourceCache interface be acceptable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions