闪烁内存缓存中存储什么? [英] What does Blink in-memory cache store?

查看:81
本文介绍了闪烁内存缓存中存储什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了浏览器缓存外,还有其他几种方法可以浏览器缓存数据。对于Chrome,呈现引擎中还有一个缓存



  • 从网络中获取HTML

  • 脚本标签脚本。 js scripts2.js 来自内存缓存

  • 图片标签 logo.png 也来自内存

  • 样式链接标签 styles.css 来自磁盘缓存:(

  • 以编程方式添加的脚本标签 scripts2.js?id = 1 来自磁盘缓存:(


有时候,我真的很幸运,所有内容都从内存缓存中提供:


我很想了解Blink内存缓存的工作方式,以及如何调整我的站点以将其用于所有带有<$适当资源的资源c $ c> cache control 标头。


----编辑----


与我有关的问题最多是:为什么根本不缓存动态添加的脚本?这对 require.js 之类的框架有明显的影响,因为它们将所有依赖项插入为动态添加的脚本标签。

解决方案

我相信这是chrome优化的结果,它们使您变得冗长。



文件始终进入磁盘缓存。并且它们也进入内存并很快被刷新。



Chrome很聪明,可以询问正在运行的进程,在查找之前,它们是否仍在内存中加载了副本磁盘。
该步骤具有较高的命中率,因为这些图像/ js正在积极地用于某些事情。



您将无法控制chrome如何管理它们的TTL /内存容量,以保持blob的高温。 Chrome开发人员团队根据实际的硬件容量和系统负载在动态调整方面做了大量工作。



P.S。如果您要求将您的APP保留在内存中。您无法采用Sun / Adob​​e的邪恶方式:通过内存图标(通过任务栏图标/服务)使它们的应用DLL处于内存中,并使其他所有人的速度变慢。



P.P.S。如果是最终用户可能要使用的应用程序,请使用electronic并遵循Whatsapp / Slack / etc来构建始终运行的应用程序。


Besides the browser cache, there are a few other ways browser cache data. For Chrome, there is another cache in the rendering engine Blink that stores images, styles, scripts and fonts (maybe more) in memory.

This cache is used for consecutive navigations on a site. Resources delivered from the Blink cache are tagged with (from memory cache) in the network tab. Resources served from the browser cache are tagged with (from disk cache).

My question is now, which resources are stored in and delivered from this very fast cache? From my tests, it varies a lot:

  • It works extremely well for images and script tag which are directly in the HTML.
  • It works sometimes for style (link) tags which are directly in the HTML. Sometimes it does not work (in the same browser with the same session).
  • It works almost never for script tags that are inserted into the HTML programmatically. Sometimes it works though.

One huge difference between disk cache hits and memory cache hits becomes visible in combination with Service Workers. Requests that are served by the in-memory cache cannot be observed in the Service Worker (because the cache comes before the Service Worker). Requests that are served by the disk cache pass through the Service Worker (since the Browser Cache lies behind Service Worker).

To show the explained behavior, I built a test page with all resource types: https://dm-clone-optimized.app.baqend.com/

You can navigate through the site with the links at the top and observe how the requests behave in the network tab and console. Every page loads the same resources.

After a bit of navigating (Chrome 70.0.3538.67), I get this behavior most of the time:

  • HTML is fetched from network
  • Script tags scripts.js and scripts2.js are from in-memory cache
  • Image tag logo.png is from in-memory as well
  • Style link tag styles.css is from disk cache :(
  • Programatically added script tag scripts2.js?id=1 is from disk cache as well :(

Sometimes though, I get really lucky and everything is served from in-memory cache:

I would love to understand how the Blink in-memory cache works and how I can tune my site to use it for all resources with appropriate cache control header.

---- edit ----

What concerns me the most is: Why are dynamically added scripts not cached at all? This has a noticeable impact on frameworks like require.js since they insert all dependencies as dynamically added script tags.

解决方案

I believe it is a result of optimization in chrome, and they make it verbose to you.

The files are always go into disk cache. And they also goes into memory, and flushed very soon.

Chrome is smart enough to ask running process that do they still have a loaded copy of them in memory before seek on disk. The step has a high hit rate, as those images/js are actively using for something.

You will not have any control how chrome manage TTL of them/capacity of memory could be used to keep blob hot. Chrome dev team doing quite a lots on dynamic tuning based on actual hardware capacity and system loading.

P.S. If you are asking for keep YOUR APP in memory. You are failing into Sun/Adobe way of evil: making their app DLL hot in memory(by tray icon/service) and slow everyone else down.

P.P.S. If it is the app end-user might want to use, use electron and follow Whatsapp/Slack/etc to build an app always running.

这篇关于闪烁内存缓存中存储什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆