[PR #653] [CLOSED] feat: lazy per-route cache seeding for Workers #746

Closed
opened 2026-05-06 13:09:55 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/653
Author: @NathanDrake2406
Created: 3/22/2026
Status: Closed

Base: mainHead: feat/seed-workers-memory-cache


📝 Commits (6)

  • 97c7a82 feat: lazy per-route cache seeding for Workers from prerendered assets
  • 8011d47 refactor: extract shared types and helpers from seed-cache modules
  • 8f46d7f fix: error resilience and transient failure recovery in Workers cache seeding
  • ee4f85b fix: resolve merge conflicts and address review comments
  • b995b0d fix: harden workers prerender cache seeding path normalization
  • 7ec76af fix: cache permanent manifest parse failures in workers seeding

📊 Changes

7 files changed (+889 additions, -61 deletions)

View changed files

📝 packages/vinext/package.json (+4 -0)
📝 packages/vinext/src/deploy.ts (+61 -13)
packages/vinext/src/server/seed-cache-shared.ts (+60 -0)
packages/vinext/src/server/seed-cache-workers.ts (+229 -0)
📝 packages/vinext/src/server/seed-cache.ts (+17 -48)
📝 tests/deploy.test.ts (+45 -0)
tests/seed-cache-workers.test.ts (+473 -0)

📄 Description

Summary

  • On Workers with MemoryCacheHandler (the default when KV is not configured), pre-rendered routes now lazily seed the memory cache on first request via env.ASSETS.fetch()
  • Seeding is per-route (not eager startup) to respect Workers' ephemeral isolate model and 128MB memory limit
  • Concurrent cold hits for the same route are deduped via an in-flight promise map

Pre-requisite

Depends on #645 for the manifest format changes (buildId, router, trailingSlash fields).

How it works

  1. Deploy time (deploy.ts): After prerendering, copies vinext-prerender.json and HTML/RSC files to dist/client/__prerender/ so they're deployed as static assets
  2. Runtime (seed-cache-workers.ts): On each request, checks if the route has prerendered data. On first miss, fetches HTML/RSC from the assets binding and populates MemoryCacheHandler. Subsequent requests in the same isolate get cache HITs
  3. Generated worker entry: Calls seedRouteFromAssets() before delegating to the RSC handler

Changes

File Change
src/server/seed-cache-workers.ts New — lazy per-route seeding with manifest caching + concurrent dedup
src/deploy.ts Copy prerender files to assets dir + add seeding call to generated worker entry
package.json Export ./server/seed-cache-workers
tests/seed-cache-workers.test.ts 9 unit tests

Scope

This is Workers memory stub support only, not the final durable caching story. For persistent caching, users should use KVCacheHandler (opt-in) with TPR for deploy-time KV population. Issue #562 tracks the generalised remote cache seeding.

Ref #561

Test plan

  • 9 unit tests: basic seeding, index route, dynamic routes, missing manifest, non-prerendered routes, already-cached no-op, concurrent dedup, manifest caching, missing RSC graceful degradation
  • 216 deploy tests pass unchanged
  • Type-aware lint clean

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/653 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/seed-workers-memory-cache` --- ### 📝 Commits (6) - [`97c7a82`](https://github.com/cloudflare/vinext/commit/97c7a8275aab94ce5fbedc59819051a18fa5c5ec) feat: lazy per-route cache seeding for Workers from prerendered assets - [`8011d47`](https://github.com/cloudflare/vinext/commit/8011d47b9a3c45aa79a69110fbd596058f70d12e) refactor: extract shared types and helpers from seed-cache modules - [`8f46d7f`](https://github.com/cloudflare/vinext/commit/8f46d7faa8f4f9440b936990eceda02749b19d2f) fix: error resilience and transient failure recovery in Workers cache seeding - [`ee4f85b`](https://github.com/cloudflare/vinext/commit/ee4f85bf71ee3ed52deed64d5c8ea4228bb31a2d) fix: resolve merge conflicts and address review comments - [`b995b0d`](https://github.com/cloudflare/vinext/commit/b995b0d7a1492f829298925644a969972038a087) fix: harden workers prerender cache seeding path normalization - [`7ec76af`](https://github.com/cloudflare/vinext/commit/7ec76affe90a159eb4394411dfb997baab5d5667) fix: cache permanent manifest parse failures in workers seeding ### 📊 Changes **7 files changed** (+889 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/package.json` (+4 -0) 📝 `packages/vinext/src/deploy.ts` (+61 -13) ➕ `packages/vinext/src/server/seed-cache-shared.ts` (+60 -0) ➕ `packages/vinext/src/server/seed-cache-workers.ts` (+229 -0) 📝 `packages/vinext/src/server/seed-cache.ts` (+17 -48) 📝 `tests/deploy.test.ts` (+45 -0) ➕ `tests/seed-cache-workers.test.ts` (+473 -0) </details> ### 📄 Description ## Summary - On Workers with `MemoryCacheHandler` (the default when KV is not configured), pre-rendered routes now lazily seed the memory cache on first request via `env.ASSETS.fetch()` - Seeding is per-route (not eager startup) to respect Workers' ephemeral isolate model and 128MB memory limit - Concurrent cold hits for the same route are deduped via an in-flight promise map ## Pre-requisite Depends on #645 for the manifest format changes (`buildId`, `router`, `trailingSlash` fields). ## How it works 1. **Deploy time** (`deploy.ts`): After prerendering, copies `vinext-prerender.json` and HTML/RSC files to `dist/client/__prerender/` so they're deployed as static assets 2. **Runtime** (`seed-cache-workers.ts`): On each request, checks if the route has prerendered data. On first miss, fetches HTML/RSC from the assets binding and populates `MemoryCacheHandler`. Subsequent requests in the same isolate get cache HITs 3. **Generated worker entry**: Calls `seedRouteFromAssets()` before delegating to the RSC handler ## Changes | File | Change | |------|--------| | `src/server/seed-cache-workers.ts` | New — lazy per-route seeding with manifest caching + concurrent dedup | | `src/deploy.ts` | Copy prerender files to assets dir + add seeding call to generated worker entry | | `package.json` | Export `./server/seed-cache-workers` | | `tests/seed-cache-workers.test.ts` | 9 unit tests | ## Scope This is **Workers memory stub support only**, not the final durable caching story. For persistent caching, users should use `KVCacheHandler` (opt-in) with TPR for deploy-time KV population. Issue #562 tracks the generalised remote cache seeding. Ref #561 ## Test plan - [x] 9 unit tests: basic seeding, index route, dynamic routes, missing manifest, non-prerendered routes, already-cached no-op, concurrent dedup, manifest caching, missing RSC graceful degradation - [x] 216 deploy tests pass unchanged - [x] Type-aware lint clean --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:55 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#746
No description provided.