根据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 次的限制似乎相当低。
非常感谢任何帮助,谢谢!
最佳答案
就您的情况而言,我认为您的问题在于长期缓存而不是内存缓存。在资源瀑布中,多个请求可以标记为已缓存。如果您愿意,可以通过多种方式来避免这种情况:
- 按 CTRL+F5,而不是正常重新加载 (F5)。这将重新加载所有资源,我通常按 CTRL+F5 几次,尽管一次就足够了。
- 如果您需要每次任何用户访问您的页面时都从服务器重新加载某些特定资源,那么您可以使用以下一些技术:
- 最优雅的方法:配置您的服务器以在 HTTP header 中返回缓存策略 https://developer.mozilla.org/es/docs/Web/HTTP/Headers/Cache-Control
- 向您的请求添加每次都不同的更改获取参数,例如使用毫秒。例如:https://www.gravatar.com/avatar/c6252fcbc3ce5fc144c11dedd75bce29?_=1501147200802其中 1501147200802 每次重新加载都是不同的。这会混淆缓存,因此每次请求时都会从服务器加载资源。
请记住仅将这些规则应用于您真正需要的资源。否则,您的网络服务器将因不必要的请求而过载。
如文档中所述:内存缓存不适用于不同的页面渲染,即使对于相同的 url 和同一选项卡(内存缓存附加到渲染进程的生命周期),所以我认为这不适用于您的情况。每次显示页面时,渲染周期都会结束,如果再次渲染,则会开始另一个周期。例如:当第一次加载图像时出现在瀑布中,但同一页面上的后续请求则不会出现。
关于google-chrome - 有人可以解释一下 Google Chrome 内存缓存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35514369/