2016-09-19 33 views
1

我刚刚进入服务人员,并为我的网站做了一个简单的设置。服务工作者保持其缓存多久?

该文档相当不错,但我无法找到任何地方有多少服务人员保持缓存?我正在为我的js和css资产(如bundle.[hash].js)进行缓存清除,我不确定是否应该确保手动清除缓存中的旧资产,还是会在一段时间内过期?

回答

-1

您是否检查过文档?

http://www.html5rocks.com/en/tutorials/service-worker/introduction/#toc-how

当我们安装,激活步骤将遵循,这是处理旧的缓存的任何管理,这 我们的服务工人在覆盖 很好的机会更新部分。

enter image description here

我挂解释说, “如何缓存并返回请求”

self.addEventListener('activate', function(event) { 

    var cacheWhitelist = ['pages-cache-v1', 'blog-posts-cache-v1']; 

    event.waitUntil(
    caches.keys().then(function(cacheNames) { 
     return Promise.all(
     cacheNames.map(function(cacheName) { 
      if (cacheWhitelist.indexOf(cacheName) === -1) { 
      return caches.delete(cacheName); 
      } 
     }) 
    ); 
    }) 
); 
}); 
0

您可以通过控制高速缓存控制器设置缓存年龄页:

public
Expires: (sometime in the future, according session.cache_expire) Cache-Control: public, max-age=(sometime in the future, according to session.cache_expire) Last-Modified: (the timestamp of when the session was last saved)

还有,

<?php header('Cache-Control: max-age=604800'); /* now get and send images */ ?>

在这里看到: enter link description here