Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain Google Chrome in-memory cache?

According to this API doc, which is the only source I've found which describes the in-memory cache:

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.

I need a better understanding of the in-memory cache. Specifically, I need Chrome to generate the full webRequest / resource waterfall every time I visit a site, including refreshing a page. Obviously, this can't be true if it's using an in-memory cache.

Is the memory cache a clean-slate for a new tab when I create a new tab?

What does "very expensive operation" mean quantitatively?

If I call handlerBehaviorChanged() every time a page is reloaded in the same tab, will that guarantee a full waterfall? In that case, a limit of 20 times over 10 minutes seems fairly low.

Any help is highly appreciated, thanks!

like image 490
Dan Chang Avatar asked Feb 19 '16 20:02

Dan Chang


People also ask

What is memory cache Chrome?

"Memory Cache" stores and loads resources to and from Memory (RAM). So this is much faster but it is non-persistent. Content is available until you close the Browser. "Disk Cache" is persistent. Cached resources are stored and loaded to and from disk.

Can I delete Chrome cache storage?

In the Chrome appAt the top, choose a time range. To delete everything, select All time. Next to “Cookies and site data” and “Cached images and files,” check the boxes. Tap Clear data.


1 Answers

In your case I think that your problem is with the long term cache instead the in-memory cache. In the resource waterfall several requests can be marked as cached. There are various manners to avoid that if you want:

  • Instead of normal reloading (F5) press CTRL+F5. That will reload all the resources, I usually press CTRL+F5 several times although one time must be suficient.
  • If you need that your page reload some specific resources from server each time any user visit you then you can use some of this techniques:
    • The most elegant: configure your server to return cache policies in the HTTP headers https://developer.mozilla.org/es/docs/Web/HTTP/Headers/Cache-Control
    • Add to your request a changing get parameter different each time, for example use milliseconds. For example: https://www.gravatar.com/avatar/c6252fcbc3ce5fc144c11dedd75bce29?_=1501147200802 where 1501147200802 is different for each reload. This will confuse cache so resource will be loaded from server each time you request it.

Remember to apply these rules only for the resources that you really need to. Otherwise your webserver will be overloaded with innecesary requests.

As stated in the document mentioned: in-memory cache does not apply to different page renderings even for the same url and in the same tab (in-memory cache is attached to the lifetime of a render process), so I think that does not apply for your case. Rendering cycle ends each time the page is displayed and a different one starts if rendered again. For example: when a image is loaded for the first time appears in the waterfall, but no for later requests on the same page.

like image 69
user1039663 Avatar answered Oct 18 '22 19:10

user1039663