google-chrome - 有人可以解释一下 Google Chrome 内存缓存吗?

标签 google-chrome google-chrome-extension

根据this API 文档,这是我找到的唯一描述内存缓存的来源:

Chrome employs two caches — an on-disk cache and a very fast in-memory cache. The lifetime of an in-memory cache is attached to the lifetime of a render process, which roughly corresponds to a tab. Requests that are answered from the in-memory cache are invisible to the web request API. If a request handler changes its behavior (for example, the behavior according to which requests are blocked), a simple page refresh might not respect this changed behavior. To make sure the behavior change goes through, call handlerBehaviorChanged() to flush the in-memory cache. But don't do it often; flushing the cache is a very expensive operation. You don't need to call handlerBehaviorChanged() after registering or unregistering an event listener.

我需要更好地了解内存缓存。具体来说,我需要 Chrome 在每次访问网站时生成完整的 webRequest/资源瀑布,包括刷新页面。显然,如果使用内存缓存,则情况不可能如此。

当我创建新选项卡时,内存缓存是否会为新选项卡重新清理?

“非常昂贵的操作”在数量上意味着什么?

如果我每次在同一选项卡中重新加载页面时都调用 handlerBehaviorChanged() ,这会保证完整的瀑布流吗?在这种情况下,10 分钟内 20 次的限制似乎相当低。

非常感谢任何帮助,谢谢!

最佳答案

就您的情况而言,我认为您的问题在于长期缓存而不是内存缓存。在资源瀑布中,多个请求可以标记为已缓存。如果您愿意,可以通过多种方式来避免这种情况:

请记住仅将这些规则应用于您真正需要的资源。否则,您的网络服务器将因不必要的请求而过载。

如文档中所述:内存缓存不适用于不同的页面渲染,即使对于相同的 url 和同一选项卡(内存缓存附加到渲染进程的生命周期),所以我认为这不适用于您的情况。每次显示页面时,渲染周期都会结束,如果再次渲染,则会开始另一个周期。例如:当第一次加载图像时出现在瀑布中,但同一页面上的后续请求则不会出现。

关于google-chrome - 有人可以解释一下 Google Chrome 内存缓存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35514369/

相关文章:

javascript - 如何更改后台文件(Chrome 扩展)中的 content_scripts?

css - 堆叠式 flex 盒垂直居中在 Chrome 中不起作用

javascript - 重定向到新的外部 url 时如何保留 localStorage

google-chrome - Selenium : pc account lockout while running Test Automation in Selenium Webdriver

google-chrome-extension - 无法使用文件或目录名称 _metadata 加载扩展

google-chrome - Chrome 中的 SVG 有时不渲染

google-chrome - Chrome 桌面通知更大尺寸

javascript - 重定向到 Chrome 扩展程序

javascript - 在 Chrome/Chromium 插件中检查互联网连接;加载的图像已缓存

facebook - Google Chrome 扩展 + 使用 Facebook 登录 + 解析