21 lines
1.2 KiB
Markdown
21 lines
1.2 KiB
Markdown
# 0052 The service worker evicts the least recently used entry first
|
|
|
|
Status: Accepted · Area: architecture · Date: 2026-10-09 · Decided by: user
|
|
|
|
## Context
|
|
Adopted from kasra-pay's decision 0033. The worker evicted the oldest entry first and never rewrote an unchanged file, so after a few deploys it deleted the chunks every page uses before the dead chunks of older deploys. It also listed the whole cache after every put.
|
|
|
|
## Decision
|
|
- The worker reads the cache's key order once per start and keeps it in memory: each put moves its entry to the end, and eviction takes from the front.
|
|
- A hit in the older half of the cache is stored again, which moves it to the end.
|
|
|
|
## Alternatives
|
|
- Oldest first (the skill's lib-pwa.md): the hottest files go first after a few deploys.
|
|
- Access times in IndexedDB: a second store, and a write on every hit.
|
|
- Store every hit again: a disk write per served file per page load.
|
|
|
|
## Consequences
|
|
- A hot file is rewritten at most once per `maxEntries / 2` new entries; with no deploys, never.
|
|
- Relies on `cache.put` moving an entry to the end of `keys()`, as the Cache API spec says.
|
|
- Only activation creates the cache, so a worker that outlives its registration (the kill switch in another tab) stores nothing.
|