api 缓存_缓存API

api 缓存

The awesome ServiceWorker API is meant to give developers a bit more control over what is and isn't cached, and how.  Sure we can play games with ETags and the like but doing it programmatically with JavaScript just feels better, more controllable.  As with every API, however, adding stuff to cache isn't just fun and games -- you have to do the cleanup work yourself too, and by "cleanup work" I mean having to delete cache.

出色的ServiceWorker API旨在使开发人员对缓存的内容和不缓存的内容以及如何进行更多控制。 当然,我们可以使用ETags等玩游戏,但是使用JavaScript以编程方式进行操作会感觉更好,更可控。 但是,与每个API一样,向缓存中添加内容不仅很有趣,而且也很有趣-您也必须自己进行清理工作,而通过“清理工作”,我的意思是必须删除缓存。

Let's have a look at how you can get caches, add and delete requests from caches, and how you can then delete an entire cache!

让我们看一下如何获取缓存,从缓存中添加和删除请求以及如何删除整个缓存!

检测cache API (Detecting the cache API)

To detect if the browser supports the Cache API...

要检测浏览器是否支持Cache API ...


if('caches' in window) {
  // Has support!
}

...check for the presence of the caches object within the window.

...检查window是否存在caches对象。

创建一个缓存 (Creating a Cache)

Creating a cache requires a caches.open call with a cache name:

创建缓存需要使用缓存名称进行caches.open调用:


caches.open('test-cache').then(function(cache) {
  // Cache is created and accessible
});

The caches.open call returns a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值