What Is The Difference Between Cache Storage and Cache Object in CacheAPI

1.1k views Asked by At

So I tried to learn cache storage and fire cache from the mozzila developer network, but I don't really understand what the basic differences are from cache storage and object cache, both have the same function

for example caches.match and cache.match have the same function of matching cache, but I don't really understand when to use one of these, maybe someone can explain more deeply the fundamental differences in CacheStorage and Cache

Reference : https://developer.mozilla.org/id/docs/Web/API/CacheStorage https://developer.mozilla.org/en-US/docs/Web/API/Cache

1

There are 1 answers

0
Kaiido On BEST ANSWER

The CacheStorage interface holds several Cache objects, like a Map of Maps if you wish.
This allows you to do versioning for instance, you can have two Cache instances which from the same Requests won't return the same Response.

Regarding their match methods, if you want to find the Response in a particular Cache Object, then you use cache.match, if you want to find it in any Cache Objects, then you use caches.match, which as MDN's article puts it

Note: caches.match() is a convenience method. Equivalent functionality is to call cache.match() on each cache (in the order returned by caches.keys()) until a Response is returned.

Other methods are pretty different since CacheStorage caches will deal with managing the different Cache objects, while Cache instances will deal with managing actual Request -> Response linking.