The put() method of the Cache interface allows key/value pairs to be added to the current Cache object.

Often, you will just want to fetch() one or more requests, then add the result straight to your cache. In such cases you are better off just using Cache.add/Cache.addAll, as they are shorthand functions for one of more of these operations:

Note: put() will overwrite any key/value pair previously stored in the cache that matches the request.

Note: Initial Cache implementations (in both Blink and Gecko) resolve Cache.add, Cache.addAll, and Cache.put promises when the response body is fully written to the disk. More recent spec versions have newer language stating that the browser can resolve the promise as soon as the entry is recorded in the database even if the response body is still streaming in.

Note: As of Chrome 46, the Cache API will only store requests from secure origins, meaning those served over HTTPS.

구문

cache.put(request, response).then(function() {
// request/response pair has been added to the cache
});

리턴

A promise that resolves with void.

Note: The promise will reject with a TypeError if the URL scheme is not http or https.

If not, open the v1 cache using open(), put the default network request in the cache using Cache.put and return a clone of the default network request using return response.clone() — necessary because put() consumes the response body.

If this fails (e.g., because the network is down), return a fallback response.