Search code examples
workbox

workbox modify creation date on access


I want to modify the creation date of the cache item when the Ressource is requested so it’s get not deleted by the expiration plugin.

Any idea how can I do this? Search in the documentation and GitHub issues but found nothing.

Any hint would be great!


Solution

  • The default behavior when using ExpirationPlugin is for the timestamp associated with each URL to be updated whenever the cached response is actually used.

    So, I think the behavior you're looking for is already implemented, but perhaps I'm missing something.

    If, for some reason, you did need to do this manually, the Advanced Usage section of the documentation has an example of creating a CacheExpiration instance directly, given a cacheName, and then you can call the updateTimestamp() method on it:

    import {CacheExpiration} from 'workbox-expiration';
    
    const expiration = new CacheExpiration('my-cache-name');
    await expiration.updateTimestamp('/my/url');