简体   繁体   English

当通过服务工作者缓存文件时,缓存变得非常臃肿,服务工作者是否在缓存隐藏文件?

[英]When caching files via service worker the cache gets very bloated, is service worker caching hidden files?

I have a service worker following this method here , outlined by Nicolas Bevacqua.我有一个服务人员在这里遵循 Nicolas Bevacqua 概述的这种方法。 The code works for me after some small tweaks.经过一些小的调整后,该代码对我有用。 But when navigating around for a while the cache gets some serious bloat.但是当浏览一段时间时,缓存会变得非常臃肿。 I've added some exclusions ie我添加了一些排除项,即

if (( event.request.url.indexOf( '/maps/' ) !== -1 ) || 
    ( event.request.url.indexOf( '/mapfiles/' ) !== -1 ) || 
    ( event.request.url.indexOf( '/maps-api-v3/' ) !== -1 ) || 
    ( event.request.url.indexOf( '/images/' ) !== -1 ) || 
    ( event.request.url.indexOf( '.mp4' ) !== -1 ) ) {
    return false;
} 

But what is strange is the cache total size is not reflective of what's in the actual caches.但奇怪的是缓存总大小并不能反映实际缓存中的内容。 There seems to be data in there that is not listed in my two caches.那里似乎有我的两个缓存中没有列出的数据。 Is there a way to stop this from happening?有没有办法阻止这种情况发生? And is the service worker caching hidden files? Service Worker 是否在缓存隐藏文件?

  1. You should be a bit more specific – "some serious bloat" is not too descriptive here =)你应该更具体一点——“一些严重的臃肿”在这里不太描述=)
  2. Total cache size being not reflective of the actual files when inspected on disk usually means that you're caching opaque responses .在磁盘上检查时,总缓存大小不反映实际文件通常意味着您正在缓存不透明的响应 When an opaque response is cached, the caches API hides the actual size of the response by saying it takes a lot of space.当缓存不透明的响应时,缓存 API 通过说它占用大量空间来隐藏响应的实际大小。 So eg.所以例如。 7 Kb file might become 7 Mb in the SW cache. 7 Kb 文件在 SW 缓存中可能变为 7 Mb。 Read more here: https://cloudfour.com/thinks/when-7-kb-equals-7-mb/在此处阅读更多信息: https://cloudfour.com/thinks/when-7-kb-equals-7-mb/
  3. I'm not sure what you mean by "data in there that is not listed in my two caches".我不确定您所说的“我的两个缓存中未列出的数据”是什么意思。 You need to provide examples of your code and screenshots from the DevTools and be more specific =)您需要提供来自 DevTools 的代码示例和屏幕截图,并且更具体 =)
  4. No, Service Worker is not caching anything by default.不,Service Worker 默认不缓存任何东西。 I'm not sure what you mean by "hidden files" but still no, Service Worker is not caching anything that you didn't ask it to cache.我不确定您所说的“隐藏文件”是什么意思,但仍然没有,Service Worker 不会缓存您没有要求它缓存的任何内容。 If you ask it to cache these "hidden files" then it will cache them.如果您要求它缓存这些“隐藏文件”,那么它将缓存它们。 But there's no automatic mechanism to do so without your knowledge.但是,在您不知情的情况下,没有自动机制可以这样做。

Hope this helps!希望这可以帮助! Feel free to ask more or update your question!随时提出更多问题或更新您的问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM