workbox 在访问时修改创建日期

workbox modify creation date on access

我想在请求资源时修改缓存项的创建日期,这样它就不会被过期插件删除。

知道我该怎么做吗? 在文档和 GitHub 问题中搜索但一无所获。

任何提示都会很棒!

使用 ExpirationPlugin 时的默认行为是 timestamp associated with each URL to be updated 每当实际使用缓存响应时。

所以,我认为您正在寻找的行为已经实现,但也许我遗漏了什么。

如果出于某种原因,您确实需要手动执行此操作,文档的高级用法部分包含 an example of creating a CacheExpiration instance directly, given a cacheName, and then you can call the updateTimestamp() 方法:

import {CacheExpiration} from 'workbox-expiration';

const expiration = new CacheExpiration('my-cache-name');
await expiration.updateTimestamp('/my/url');