Cache Interface (Web API) Overview The Cache interface provides persistent storage for Request/Response object pairs in long-lived memory, accessible from both windowed scopes and workers. It does not automatically update or expire cached items; explicit management by the developer is required. Multiple named cache objects can exist per origin. Cache lifecycle is browser-dependent, but cached data generally persists across sessions. Browser storage limits apply; browsers may clear cache storage to manage disk space. Cache usage quota can be estimated using StorageManager.estimate(). Cache API ignores HTTP caching headers. Cache key matching considers the VARY header for precise differentiation. Important Notes Available only in secure contexts (HTTPS). Supported inside Web Workers. Cache entries do not store or handle cookies (Set-Cookie headers removed). Instance Methods | Method | Description | |--------------------------|-----------------------------------------------------------------------------------------------------------| | Cache.match(request) | Returns a promise resolving to the first response matching the request in the cache. | | Cache.matchAll(request) | Returns a promise resolving to an array of all cached responses matching the request. | | Cache.add(url) | Fetches a URL and stores the response in the cache (equivalent to fetch() then put()). | | Cache.addAll(urls) | Fetches multiple URLs and stores all resulting responses in the cache. | | Cache.put(request, response) | Adds a request-response pair explicitly to the cache. | | Cache.delete(request) | Deletes the cache entry for the given request; resolves to true if found and deleted, otherwise false.| | Cache.keys() | Returns a promise resolving to an array of all cache keys (requests). | Example: Selective Caching in a Service Worker A service worker example demonstrates: Opening a named cache (font-cache-v1) using CacheStorage.open(). Checking for cached font resources using cache.match(). Fetching and caching fonts only if not already cached. Checking Content-Type for "font/" to selectively cache font files. Handling errors from fetch operations gracefully. Versioning and deleting old caches not in use to avoid stale data.