Skip to content

fix(web): bypass data cache for large reference categories#141

Merged
ntatschner merged 1 commit into
nextfrom
fix/web-reference-items-cache
May 31, 2026
Merged

fix(web): bypass data cache for large reference categories#141
ntatschner merged 1 commit into
nextfrom
fix/web-reference-items-cache

Conversation

@ntatschner
Copy link
Copy Markdown
Collaborator

Summary

  • Next 15 hardcodes a 2 MB per-entry limit on the fetch data cache. The items reference listing weighs ~3.4 MB (and vehicle ~4 MB per memory/wiki-reference-page-sizes.md), so every render calling getCategoryBundle('item') / getCategoryBundle('vehicle') logged Failed to set Next.js data cache for … items over 2MB can not be cached (3441446 bytes) and silently failed the cache write.
  • kbCacheOpts now takes the category as an optional arg and returns cache: 'no-store' for the known-large set (LARGE_CATEGORIES = { item, vehicle }). Other categories (weapon, location) keep the 1h revalidate. STARSTATS_DISABLE_FETCH_CACHE=1 still wins globally for the Playwright scenario-isolation path.
  • React's request-level fetch dedup still applies — same-URL fetches within a single server render share an upstream call regardless of cache mode. The 3.4 MB inbound transfer per page render touching items is the same cost we were already paying because Next refused to cache it anyway.

If a third category ever crosses 2 MB the symptom is the same log line — add it to LARGE_CATEGORIES.

Test plan

  • pnpm --filter web run test:run — 30 tests pass (6 new in reference.test.ts: large-category set membership, revalidate default + small categories, no-store for large categories, STARSTATS_DISABLE_FETCH_CACHE global override)
  • pnpm --filter web run typecheck — clean
  • pnpm --filter web run lint — no new warnings (3 pre-existing remain in unrelated files)
  • Smoke: after merge + platform promote, watch starstats-web logs and confirm the "Failed to set Next.js data cache" warning stops firing for /v1/reference/item and /v1/reference/vehicle requests.

…icle)

Next 15 hardcodes a 2 MB per-entry limit on the fetch data cache.
The items reference listing currently weighs ~3.4 MB and the
vehicle listing ~4 MB (per memory/wiki-reference-page-sizes.md), so
every render that calls `getCategoryBundle('item')` /
`getCategoryBundle('vehicle')` logged:

  Failed to set Next.js data cache for
  http://starstats-api:8080/v1/reference/item,
  items over 2MB can not be cached (3441446 bytes)

The fetch still succeeded — pages rendered fine — but the cache
attempt was wasted serialization work and the recurring warning
muddied the prod logs.

Fix: `kbCacheOpts` now takes the category as an optional arg and
returns `cache: 'no-store'` for the known-large set (LARGE_CATEGORIES
= item + vehicle). Other categories (weapon, location) keep the 1h
revalidate. STARSTATS_DISABLE_FETCH_CACHE=1 still wins for the
Playwright scenario-isolation path.

React's request-level fetch dedup still applies — same-URL fetches
within a single server render share an upstream call regardless of
cache mode. The cost is one 3.4 MB inbound transfer per page render
that touches items, which is the cost we were already paying because
Next refused to cache it anyway.

If a third category ever crosses 2 MB the symptom is the same log
line; add it to LARGE_CATEGORIES.
@ntatschner ntatschner merged commit bd272c8 into next May 31, 2026
9 checks passed
@ntatschner ntatschner deleted the fix/web-reference-items-cache branch May 31, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant