Web APIs
Cache.prototype.put()
Stores an eligible request/response pair, consuming the supplied response body; resolves when the operation completes.
Formal Syntax & Structure
javascript syntaxjavascript
cache.put(request, response)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| request | Request | string | Eligible GET request or URL. |
| response | Response | Eligible response to store. |
Return Value
Promise<undefined>
Stores an eligible request/response pair, consuming the supplied response body; resolves when the operation completes.
Working Example
Example Snippetjavascript
(async () => {const name="bm-v14-"+crypto.randomUUID();try{const c=await caches.open(name),url=new URL("v14-item",location.href).href,r=new Response("saved");await c.put(url,r.clone());console.log(await r.text(),await (await c.match(url)).text());}finally{await caches.delete(name);}})()