Cache Matching Options
You'll learn: How to use special options to make the Cache API more flexible when finding stored responses.
When you ask the Cache API to retrieve a cached response with cache.match(request), you can pass an options object as a second argument to control how the matching happens. By default, the Cache API is strict—it looks for an exact match of the request URL and method. But sometimes you want more flexibility.
The Three Main Matching Options
ignoreSearch: When true, the Cache API ignores query string parameters when matching URLs. For example, /page?theme=dark would match a cached /page?theme=light or even just /page.
ignoreMethod: When true, the Cache API ignores the HTTP method (GET, POST, etc.) and only compares URLs. This is useful when you cache a GET request but want to retrieve it for any method type.
ignoreVary: When true, the Cache API ignores the Vary response header, which normally tells the cache to store separate versions based on request headers like Accept-Language. Setting this to true means "just give me any cached version, regardless of variations."
Why This Matters
Imagine your site caches product pages, but users might arrive via URLs with tracking parameters like ?utm_source=email. Without ignoreSearch, those would be treated as completely different pages. With it, you can serve the same cached page regardless of query strings.
cache.match('/products/123?ref=promo', {
ignoreSearch: true
});
// Will match a cached '/products/123' entry
Key Takeaway: Cache matching options (ignoreSearch, ignoreMethod, ignoreVary) let you control how strictly the Cache API compares requests, enabling more flexible and efficient caching strategies.