Skip to content

cache tier

Eugene Lazutkin edited this page Jul 5, 2026 · 2 revisions

Cache tier

The shared Cache API tier every tab sees — and everything else on the origin too: parts unpacked from bundles, transport prefetches, and page-side write-through all land here, and unadorned fetch() benefits once the worker serves from it.

import {createCacheTier} from 'double-meh-sw/cache-tier.js';

const tier = createCacheTier({cacheName: 'app-shared'});

Serve-first by design

handleFetch(request) answers from the cache or passes (undefined); requests carrying x-io-no-cache always pass. Plain network responses are not stored unless the store predicate opts them in — the tier's writers are the bundle window's parts, the io:fetch transport, and pages writing through the same Cache API. That keeps the tier deliberate: it holds what something chose to put there.

put(target, response) stores 2xx responses only. invalidate(pattern) takes a URL prefix, RegExp, or predicate and returns the eviction count — it backs the io:invalidate message.

Platform notes

The browser Cache API honors Vary on match natively. Deno (a test runtime, not a deployment target) ships the Cache API without keys() — the tier feature-detects and falls back to exact-URL eviction there.

See also: The assembly, Messages.

Clone this wiki locally