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?
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?
Chrome implements caches at many levels of abstraction. At the core there is HTTP (Browser) cache - a backend for other caching mechanisms. Generally caches could be divided into:
HTTP Cache Service Worker Caches Blink cache HTTP Cache
Every request that is made over the network is proxied by HTTP Cache adhering to RFC. When requested for the first time cache is overwritten. Resources are keyed by the origin url.
Service Worker Cache
To gracefully handle network connection failures you could use Service Workers. The caches and cache storage would be taken from disk again.
Blink Cache
Blink uses Http Cache as backend in two modes of creation - in memory and simple (filesystem). Which one is used depends on limit set globally for caches how much memory they can take. Also the current renderer cache gets the most share. What is cached are fonts, images and scripts. If global memory usage reaches some specified threshold then filesystem backend is used.
Forcing in memory cache
If you want your files to be served from memory overriding default mechanism, you can implement your own Service Worker. Using File Api, resources can be read and stored into object in memory. Then overriding fetch event would suppress network and file reads with content served from this global object.
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.
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.