javascript - 从通过 CacheStorage api 通过 cache.match(req) 返回的响应中检索“时间缓存”
问题描述
我正在使用新的 CacheStorage api,并希望有一个小工作来清理高于某个 ttl(生存时间)的旧缓存条目。
在 Chrome 开发工具 - > 应用程序选项卡中,我看到一个“缓存时间”列,但无法通过 api 检索它。
const cache = await caches.open(`my-cache`);
const response = await cache.match(new Request(`https://someurl`))
console(response.cachedTime) <- // doesn't exist
我尝试通过 Date 标头获取它,但这仅适用于非 cors 请求。devtools 以某种方式跟踪所有请求。有没有办法通过 CacheStorage api 动态获取这些信息?
// this is not a bullet proof method
// doesn't work for cors or if response doesn't send a Date header
console.log(response.headers.get(`date`));
尝试转储整个响应并检查它,但我没有看到任何有用的东西。
解决方案
推荐阅读
- java - 使用 Gradle 激活 Lombok 注释处理器
- litedb - 如何在 LiteDB 中的 List<> 属性上进行分组
- git - 是否可以轻松地在本地开发和在 heroku 上生产不同的配置文件?
- highcharts - 通过 Socket.IO 更新桑基图
- sql-server - 部署项目时找不到“ISServerExec.exe”的路径
- reactjs - reactjs 和 redux 中的简单动作和动作创建者有什么区别?
- javascript - 按年、月和周数获取一周的开始和结束日期
- java - Spring boot Thymeleaf 根据其他下拉列表选择填充下拉列表
- javascript - 如何使用 Puppeteer 确认 ng-show (Angular) 弹出窗口?
- docker - 从 Docker Run 命令设置卷主机路径