EpubPageCacheService.clear() does not abort in-flight tap — late pages re-fill the LRU #1104

Closed
opened 2026-08-13 14:42:35 +00:00 by spikerj · 1 comment
Owner

EpubPageCacheService.clear() empties the LRU Map and the in-flight Map, but it does not unsubscribe the live getEpubPage pipes.

Those pipes still tap((content) => this.store(key, content)) when the network responds. After a reader calls clear() (e.g. book change / logout), a late in-flight page is written back into the cache. A subsequent get() for that key then serves the stale book’s HTML without hitting the network.

Repro (unit):

  1. get(book, 7) with a pending Subject
  2. clear()
  3. Subject emits
  4. get(book, 7) is a cache hit — no ReaderService.getEpubPage call

Fix: keep a Subscription (or takeUntil) per in-flight key and unsubscribe in clear(), or drop the tap store when the cache generation has changed.

`EpubPageCacheService.clear()` empties the LRU Map and the in-flight Map, but it does **not** unsubscribe the live `getEpubPage` pipes. Those pipes still `tap((content) => this.store(key, content))` when the network responds. After a reader calls `clear()` (e.g. book change / logout), a late in-flight page is written back into the cache. A subsequent `get()` for that key then serves the stale book’s HTML without hitting the network. Repro (unit): 1. `get(book, 7)` with a pending Subject 2. `clear()` 3. Subject emits 4. `get(book, 7)` is a cache hit — no `ReaderService.getEpubPage` call Fix: keep a Subscription (or `takeUntil`) per in-flight key and unsubscribe in `clear()`, or drop the `tap` store when the cache generation has changed.
Author
Owner

Resolved in spikersoft-angular PR #818 (merged to master). EpubPageCacheService.clear() now unsubscribes in-flight fetches so a late page cannot refill the LRU. Closing.

Resolved in spikersoft-angular [PR #818](https://git.spikersoft.com/spikerj/spikersoft-angular/pulls/818) (merged to `master`). `EpubPageCacheService.clear()` now unsubscribes in-flight fetches so a late page cannot refill the LRU. Closing.
Sign in to join this conversation.