81

I knew that Google Chrome supports from memory cache and from disk cache when I request resources. However, I didn't see from memory cache before.

How does chrome determine which resources should be cached in memory?

enter image description here

Joe Taras
  • 15,166
  • 7
  • 42
  • 55
gentlejo
  • 2,690
  • 4
  • 26
  • 31
  • I'm interested in this. Did you ever find out how Chrome decides what goes into its disk cache, in particular? There is a popularity algorithm, I can see that just from watching what gets served from the disk cache. – Tom Dec 20 '18 at 09:09
  • Does this answer your question? [Chrome memory cache vs disk cache](https://stackoverflow.com/questions/44596937/chrome-memory-cache-vs-disk-cache) – spicy.dll Nov 02 '21 at 13:59
  • 1
    Paraphrasing the top answer: memory cache is used by default but must be cleared when Chrome exits (because Chrome is removed from memory). When Chrome starts again, these cache files must be loaded from disk back into memory. So the first cache load after Chrome closes and reopens comes from the disk. – spicy.dll Nov 02 '21 at 14:05

4 Answers4

1

The Chrome browser mostly looks at the cache-control header from the response header; if this header has immutable it will store the response to disk. Memory cache is loaded from the RAM so that which is much faster than disk cache & Memory cache is not persisted while close the tab cache will be cleared but disk cache will be retained till that expires. This is one of the primary reasons why browsers have greater memory allotted to them.

You may also need to understand this Memory Cache vs Disk Cache

Refer HTTP Cache chart so that you can easily understand cache flows

Gajarajan K
  • 459
  • 4
  • 9
0

The browser inspects the headers of the HTTP response generated by the web server. There are four headers commonly used for caching: ETag, Cache-Control, Expires, Last-Modified.

Michael De Soto
  • 1,238
  • 12
  • 24
  • 2
    While helpful context about how browsers determine what to cache, you leave the OP's question unanswered: How does Chrome determine what should be cached in memory vs. disk? – Michael De Soto Aug 16 '22 at 20:09
0

A number of factors:

  • Resource size: the smaller the resource, the more likely it is to be cached in memory.
  • Frequency of access: the more frequently a resource is accessed the more likely it is to be cached.
  • Security: the more secure the resource (https origin), the more likely it is to be cached.
  • User's browsing habits: the more frequently a user visits a site, the more likely Chrome is to store some of its resources in memory.
  • Resource type: images and scripts which are often used across multiple pages on a site are likely to be cached in memory so as to avoid re-downloading them as the user navigates between different pages.
Rene
  • 105
  • 2
  • 5
-1

Using this document, the Caching section in particular, I understand that there are two caches, an on-disk cache and a very fast in-memory cache.

As for your actual question, how does Chrome decide what gets cached where, I believe the next line provides the answer

The lifetime of an in-memory cache is attached to the lifetime of a render process, which roughly corresponds to a tab

While I am not entirely sure, I believe the in memory cache serves the current tab.

Eric
  • 6,563
  • 5
  • 42
  • 66
mayk93
  • 1,489
  • 3
  • 17
  • 31
  • 1
    It is possible to get something into memory cache by using `` but any subsequent requests to that resource in the same tab will come from disk cache. This makes your assumption incorrect: _"I believe the in memory cache serves the current tab."_ – Juice10 Sep 09 '21 at 15:16