undici exports a top-levelDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/undici/llms.txt
Use this file to discover all available pages before exploring further.
caches instance that implements the W3C CacheStorage and Cache APIs. This allows you to store and retrieve Request/Response pairs programmatically using the same interface available in browser Service Workers.
The
caches API is for programmatic cache management. For automatic HTTP response caching based on Cache-Control headers, use interceptors.cache instead.Importing
CacheStorage
Thecaches export is a singleton CacheStorage instance.
caches.open(cacheName)
Opens a named cache, creating it if it doesn’t exist. If you open a cache with the same name twice, both instances share the same underlying response list.
Opening a cache
The name of the cache to open.
Promise<Cache>
caches.has(cacheName)
Returns true if a cache with the given name exists.
caches.delete(cacheName)
Deletes a named cache. Existing Response objects from the deleted cache remain usable.
caches.keys()
Returns all cache names.
Cache
cache.put(request, response)
Stores a response for a given request.
cache.match(request[, options])
Returns the first matching response, or undefined if none found.
cache.matchAll(request[, options])
Returns all matching responses.
cache.add(request)
Fetches a URL and stores the response in the cache.
cache.addAll(requests)
Fetches multiple URLs and caches all responses.
cache.delete(request[, options])
Removes cached entries matching the request.
cache.keys([request[, options]])
Returns cached request keys.
Version-based caching pattern
A common pattern is versioning caches to handle cache invalidation:Cache versioning pattern
For more details, see the MDN CacheStorage and MDN Cache documentation.