> ## Documentation Index > Fetch the complete documentation index at: https://bunny.net/docs/llms.txt > Use this file to discover all available pages before exploring further. # Reading & writing > Reading from, writing to, and deleting entries on a Cache instance. ## Cache-Control behavior Cache entry lifetimes are controlled via the `Cache-Control` header on the response you pass to `put()`. The same directives that govern HTTP caching apply here. For the full directive list, see [Cache-Control on MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control). ```typescript theme={null} await cache.put( `${url.origin}/example.html`, new Response("content", { headers: { "Cache-Control": "max-age=60" }, }), ); ``` This caches the string `content` under the key `/example.html` for 60 seconds. ## Instance methods ### Delete The `delete()` method finds the Cache entry whose key matches the request and removes it, returning `true` if an entry was found and deleted, or `false` if there was no matching entry. #### Syntax ```typescript theme={null} await cache.delete(request); ``` Unlike the browser Cache API, Bunny Edge Scripting does not support the options bag (`ignoreSearch`, `ignoreMethod`, `ignoreVary`). To get equivalent behaviour, normalize the key at `put()` time, for example by stripping query strings from the URL before calling `put()`. #### Parameters `request` The Request you are looking to delete. This can be a Request object or a URL. #### Return Value A `Promise` that resolves to `true` if a matching entry was found and removed, or `false` if no entry existed. After the promise resolves, a subsequent `cache.match()` for the same key will miss. #### Exceptions Can throw an exception if there is an issue accessing the underlying cache storage. #### Example ```typescript theme={null} const cache = await caches.open("cache:v1"); const deleted = await cache.delete(`${url.origin}/example.html`); ``` See [Refresh and purge a cached value on demand](https://bunny.net/docs/scripting/cache/examples.md#refresh-and-purge-a-cached-value-on-demand) for a full request handler that exposes `DELETE` as a purge endpoint. ### Match The `match()` method of the Cache returns a Promise that resolves to the Response associated with the first matching request in the Cache object. If no match is found, the Promise resolves to `undefined`. #### Syntax ```typescript theme={null} await cache.match(request); ``` Unlike the browser Cache API, Bunny Edge Scripting does not support the options bag (`ignoreSearch`, `ignoreMethod`, `ignoreVary`). You can accomplish equivalent behaviour by removing query strings or unwanted headers from the key at `put()` time. #### Parameters `request` The Request for which you are attempting to find responses in the Cache. This can be a Request object or a URL. #### Return Value A `Promise` that resolves to the first `Response` that matches the request or to `undefined` if no match is found. #### Exceptions Can throw an exception if there is an issue accessing the underlying cache storage. #### Example ```typescript theme={null} const cache = await caches.open("cache:v1"); const hit = await cache.match(`${url.origin}/example.html`); if (hit) return hit; ``` See [Quickstart](https://bunny.net/docs/scripting/cache/examples.md#quickstart) for a full handler that pairs a `match()` lookup with an `HTMLRewriter` transform. ### Put The `put()` method of the Cache allows key/value pairs to be added to the current Cache object. #### Syntax ```typescript theme={null} await cache.put(request, response); ``` #### Parameters `request` The Request object or URL that you want to add to the cache. `response` The Response you want to match up to the request. #### Return Value A `Promise` that resolves with `undefined`. The promise can resolve without storing an entry. This happens when the connected Pull Zone has **Cache expiration time** set to **Override: do not cache**. See [Pull Zone cache settings](https://bunny.net/docs/scripting/cache/index.md#pull-zone-cache-settings). #### Exceptions Can throw an exception if there is an issue accessing the underlying cache storage. #### Example ```typescript theme={null} const cache = await caches.open("cache:v1"); // clone() so the response body can still be returned to the caller. await cache.put(`${url.origin}/example.html`, response.clone()); ``` See [Updating a cache in middleware](https://bunny.net/docs/scripting/cache/examples.md#updating-a-cache-in-middleware) for a full handler that populates the cache in response to origin requests. ## References * [Examples](https://bunny.net/docs/scripting/cache/examples.md): end-to-end recipes for cache-aside, middleware writes, and refresh and purge. * [Managing caches](https://bunny.net/docs/scripting/cache/managing-caches.md): the global `caches` object and named cache instances. * [Cache API overview](https://bunny.net/docs/scripting/cache/index.md): regional behavior, limitations, and API surface. This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.