The Cache object
The Cache interface is a collection of methods and properties to manage stored responses. You cannot create a cache object; you must open a reference to a cache using the Caches.open
method, which will be covered later. This reference is an instance of the Cache object, giving you access to the responses it manages.
cache.match()
The match
method has two parameters, a request
object and an optional options object. It returns a promise if a matching response is found to be resolved in the promise's return. If no response was found, the promise still resolves, but as undefined.
If no match was found, you can then continue with the appropriate logic, like forwarding the request to the network or returning a fallback response.
The request
object parameter can be either a valid request
object or a URL. If only a URL is provided, the method does an implicit conversion internally. Supplying a request
object gives you more control because different responses could be cached by request...