Workbox 只缓存时间戳到 indexDb,如何拦截 indexDb 中的 json 数据? [英] Workbox is caching only time stamps to indexDb, how to intercept with json data in indexDb?

查看:69
本文介绍了Workbox 只缓存时间戳到 indexDb,如何拦截 indexDb 中的 json 数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的路由定义了将json数据作为MyCachedData存储在缓存中,IndexDb只存储url和时间戳.

Below route defines to store json data as MyCachedData in cache storage, and IndexDb only stores the url and timestamp.

workboxSW.router.registerRoute('/MyApi(.*)',
workboxSW.strategies.staleWhileRevalidate({
    cacheName: 'MyCachedData',
    cacheExpiration: {
        maxEntries: 50
    },
    cacheableResponse: {statuses: [0, 200]}
 })
);

是否可以仅将json数据存储在索引数据库中,您如何定义它以使用Workbox拦截(添加,更新,删除)?

Is it possible to store the json data in the index db only and how can you define it to intercept (add, update, delete) using Workbox?

推荐答案

不,Workbox 依赖于 缓存存储 API 用于存储响应正文.(正如您所观察到的,它使用 IndexedDB 来处理一些带外管理信息,例如时间戳,用于缓存过期.)

No, Workbox relies on the Cache Storage API to store the bodies of responses. (As you've observed, it uses IndexedDB for some out-of-band housekeeping info, like timestamps, used for cache expiration.)

如果使用缓存存储 API 的方法不适合您的用例(很高兴听到为什么不适合?),那么我建议直接更新 IndexedDB,也许通过像 idb-keyval.

If an approach that uses the Cache Storage API isn't appropriate for your use case (it would be good to hear why not?), then I'd recommend just updating IndexedDB directly, perhaps via a wrapper library like idb-keyval.

这篇关于Workbox 只缓存时间戳到 indexDb,如何拦截 indexDb 中的 json 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆