{
  "type": "module",
  "source": "doc/api/api-cachestorage.md",
  "modules": [
    {
      "textRaw": "CacheStorage",
      "name": "cachestorage",
      "introduced_in": "v5.22.1",
      "type": "module",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>undici provides a spec-compliant implementation of the <a href=\"https://w3c.github.io/ServiceWorker/#cachestorage-interface\">W3C Service Worker\n<code>CacheStorage</code></a> and <a href=\"https://w3c.github.io/ServiceWorker/#cache-interface\"><code>Cache</code></a> interfaces. A <code>CacheStorage</code> is a named\ncollection of <a href=\"https://w3c.github.io/ServiceWorker/#cache-interface\"><code>Cache</code></a> objects, each of which stores <code>Request</code>/<code>Response</code>\npairs.</p>\n<p>The class itself is not exported; instead, undici exposes a single shared\n<code>CacheStorage</code> instance named <code>caches</code>. Import it from <code>'undici'</code>:</p>\n<pre><code class=\"language-mjs\">import { caches } from 'undici'\n\nconst cache = await caches.open('v1')\n</code></pre>\n<pre><code class=\"language-cjs\">const { caches } = require('undici')\n\ncaches.open('v1').then((cache) => {\n  // ...\n})\n</code></pre>",
      "modules": [
        {
          "textRaw": "`caches`",
          "name": "`caches`",
          "type": "module",
          "meta": {
            "added": [
              "v5.22.1"
            ],
            "changes": []
          },
          "desc": "<ul>\n<li>Type: <a href=\"https://developer.mozilla.org/docs/Web/API/CacheStorage\"><code>&#x3C;CacheStorage></code></a></li>\n</ul>\n<p>The shared <a href=\"#class-cachestorage\"><code>CacheStorage</code></a> instance exported by undici.\nAll caches opened through <code>caches</code> live for the lifetime of the process.</p>\n<pre><code class=\"language-mjs\">import { caches } from 'undici'\n\nawait caches.open('v1')\nconsole.log(await caches.keys()) // ['v1']\n</code></pre>",
          "displayName": "`caches`"
        }
      ],
      "classes": [
        {
          "textRaw": "Class: `CacheStorage`",
          "name": "CacheStorage",
          "type": "class",
          "meta": {
            "added": [
              "v5.22.1"
            ],
            "changes": []
          },
          "desc": "<p>Represents the storage for <a href=\"https://w3c.github.io/ServiceWorker/#cache-interface\"><code>Cache</code></a> objects. Each <code>CacheStorage</code> keeps a\nmapping of cache names to their backing list of cached responses.</p>\n<p>The constructor is not public: attempting to instantiate <code>CacheStorage</code>\ndirectly throws a <code>TypeError</code>. Use the exported <a href=\"#caches\"><code>caches</code></a> instance\ninstead.</p>",
          "methods": [
            {
              "textRaw": "`caches.match(request[, options])`",
              "name": "match",
              "type": "method",
              "meta": {
                "added": [
                  "v5.22.1"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`request` {Request|string} The request to match against. A string is treated as a URL.",
                      "name": "request",
                      "type": "Request|string",
                      "desc": "The request to match against. A string is treated as a URL."
                    },
                    {
                      "textRaw": "`options` {Object} (optional)",
                      "name": "options",
                      "type": "Object",
                      "desc": "(optional)",
                      "options": [
                        {
                          "textRaw": "`ignoreSearch` {boolean} When `true`, ignores the query string of the URL when matching. **Default:** `false`.",
                          "name": "ignoreSearch",
                          "type": "boolean",
                          "default": "`false`",
                          "desc": "When `true`, ignores the query string of the URL when matching."
                        },
                        {
                          "textRaw": "`ignoreMethod` {boolean} When `true`, prevents matching operations from validating the `Request` `http` method. **Default:** `false`.",
                          "name": "ignoreMethod",
                          "type": "boolean",
                          "default": "`false`",
                          "desc": "When `true`, prevents matching operations from validating the `Request` `http` method."
                        },
                        {
                          "textRaw": "`ignoreVary` {boolean} When `true`, ignores the `Vary` header when matching. **Default:** `false`.",
                          "name": "ignoreVary",
                          "type": "boolean",
                          "default": "`false`",
                          "desc": "When `true`, ignores the `Vary` header when matching."
                        },
                        {
                          "textRaw": "`cacheName` {string} When set, restricts the search to the cache with this name. **Default:** `undefined`.",
                          "name": "cacheName",
                          "type": "string",
                          "default": "`undefined`",
                          "desc": "When set, restricts the search to the cache with this name."
                        }
                      ],
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} Fulfills with the first matching {Response}, or `undefined` if no response matched.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "Fulfills with the first matching {Response}, or `undefined` if no response matched."
                  }
                }
              ],
              "desc": "<p>Searches the caches for a response matching <code>request</code>. When <code>options.cacheName</code>\nis provided, only that cache is searched; otherwise every cache is searched in\ninsertion order and the first match is returned.</p>\n<pre><code class=\"language-mjs\">import { caches } from 'undici'\n\nconst response = await caches.match('https://example.com/data', {\n  cacheName: 'v1'\n})\n</code></pre>"
            },
            {
              "textRaw": "`caches.has(cacheName)`",
              "name": "has",
              "type": "method",
              "meta": {
                "added": [
                  "v5.22.1"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`cacheName` {string} The name of the cache to look up.",
                      "name": "cacheName",
                      "type": "string",
                      "desc": "The name of the cache to look up."
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} Fulfills with `true` if a cache named `cacheName` exists, otherwise `false`.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "Fulfills with `true` if a cache named `cacheName` exists, otherwise `false`."
                  }
                }
              ],
              "desc": "<p>Checks whether a cache with the given name exists in the storage.</p>\n<pre><code class=\"language-mjs\">import { caches } from 'undici'\n\nawait caches.open('v1')\nconsole.log(await caches.has('v1')) // true\nconsole.log(await caches.has('v2')) // false\n</code></pre>"
            },
            {
              "textRaw": "`caches.open(cacheName)`",
              "name": "open",
              "type": "method",
              "meta": {
                "added": [
                  "v5.22.1"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`cacheName` {string} The name of the cache to open.",
                      "name": "cacheName",
                      "type": "string",
                      "desc": "The name of the cache to open."
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} Fulfills with the {Cache} named `cacheName`.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "Fulfills with the {Cache} named `cacheName`."
                  }
                }
              ],
              "desc": "<p>Opens the cache named <code>cacheName</code>, creating it if it does not already exist.</p>\n<p>Each call returns a new <a href=\"https://w3c.github.io/ServiceWorker/#cache-interface\"><code>Cache</code></a> object, but caches opened with the same name\nshare their underlying list of cached responses. As a result, a response stored\nthrough one instance is visible through another instance with the same name.</p>\n<pre><code class=\"language-mjs\">import { caches } from 'undici'\nimport assert from 'node:assert'\n\nconst cache1 = await caches.open('v1')\nconst cache2 = await caches.open('v1')\n\n// open() returns distinct objects,\nassert(cache1 !== cache2)\n// but they share the same cached responses.\nassert.deepStrictEqual(await cache1.match('/req'), await cache2.match('/req'))\n</code></pre>"
            },
            {
              "textRaw": "`caches.delete(cacheName)`",
              "name": "delete",
              "type": "method",
              "meta": {
                "added": [
                  "v5.22.1"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`cacheName` {string} The name of the cache to delete.",
                      "name": "cacheName",
                      "type": "string",
                      "desc": "The name of the cache to delete."
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} Fulfills with `true` if the cache existed and was deleted, otherwise `false`.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "Fulfills with `true` if the cache existed and was deleted, otherwise `false`."
                  }
                }
              ],
              "desc": "<p>Removes the cache named <code>cacheName</code> from the storage. Any <a href=\"https://w3c.github.io/ServiceWorker/#cache-interface\"><code>Cache</code></a> objects\nalready obtained for that name, along with the <code>Request</code>/<code>Response</code> pairs they\nreturned, remain usable after deletion.</p>\n<pre><code class=\"language-mjs\">import { caches } from 'undici'\n\nconst cache = await caches.open('v1')\nconst response = await cache.match('/req')\n\nawait caches.delete('v1')\n\n// The already-retrieved response is still usable.\nawait response.text()\n</code></pre>"
            },
            {
              "textRaw": "`caches.keys()`",
              "name": "keys",
              "type": "method",
              "meta": {
                "added": [
                  "v5.22.1"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [],
                  "return": {
                    "textRaw": "Returns: {Promise} Fulfills with a {string}[] of cache names in insertion order.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "Fulfills with a {string}[] of cache names in insertion order."
                  }
                }
              ],
              "desc": "<p>Returns the names of all caches currently held by the storage.</p>\n<pre><code class=\"language-mjs\">import { caches } from 'undici'\n\nawait caches.open('v1')\nawait caches.open('v2')\nconsole.log(await caches.keys()) // ['v1', 'v2']\n</code></pre>"
            }
          ]
        }
      ]
    }
  ]
}