We will use five methods to interact with the Cache API: open, addAll, match, keys, and delete. In the following, Caches will refer to the Cache API itself, and Cache to a specific cache object, to distinguish between methods called on an individual cache versus the API itself:
- Caches.open() takes a cache object name (also known as a cache key) as an argument (it can be any string), and either creates a new cache object or opens an existing one by the same name. It returns a Promise that resolves with the cache object as a parameter, which we can then use.
- Cache.addAll() takes in an array of URLs. It'll then go fetch those URLs from the server, and store the resulting file in the current cache object. Its little cousin is Cache.add ...