Skip to content

feat(registry): edge cache /api/registry/** via Nitro routeRules#36

Merged
amondnet merged 5 commits into
mainfrom
amondnet/loud-blackberry
Apr 8, 2026
Merged

feat(registry): edge cache /api/registry/** via Nitro routeRules#36
amondnet merged 5 commits into
mainfrom
amondnet/loud-blackberry

Conversation

@amondnet

@amondnet amondnet commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Cache /api/registry/** responses at the Cloudflare edge via Nitro routeRules. On a cache HIT the Pages Worker is bypassed entirely via the Cache API, cutting Worker CPU/request cost and improving CLI latency for repeat ask docs add lookups.

  • Browsers / CLI: 5 min fresh
  • Cloudflare edge: 1 h fresh + 24 h stale-while-revalidate

Route rules are extracted to apps/registry/app/route-rules.ts so the assertion test can import the constants directly without pulling in Nuxt's auto-import graph.

Closes #34

Changes

  • apps/registry/app/route-rules.ts — new, exports REGISTRY_CACHE_CONTROL + registryApiRouteRules
  • apps/registry/nuxt.config.ts — wire routeRules: registryApiRouteRules
  • apps/registry/test/nuxt-config.test.ts — new, static config assertion (bun test)
  • apps/registry/package.json — add test script
  • .please/docs/tracks/active/registry-edge-cache-20260408/ — track artifacts

Verification Checklist

  • AC-2: Automated test asserts exact cache-control header matches public, max-age=300, s-maxage=3600, stale-while-revalidate=86400 (bun run --cwd apps/registry test)
  • AC-4: No regression — bun run --cwd packages/cli test → 227 pass / 0 fail
  • AC-1 (post-deploy): curl -sI https://<pages-url>/api/registry/vercel/next.js twice → second call shows cf-cache-status: HIT
  • AC-3 (post-deploy): Registry markdown change visible within max-age + swr window without manual purge
  • AC-5 / AC-6: Deferred (ETag + deploy-purge — out of scope per track plan)

Out of Scope

  • ETag / If-None-Match (follow-up track)
  • Deploy-hook cache purge (ship only if staleness becomes painful)
  • Caching the future raw-docs API

Test Plan

  • bun run --cwd apps/registry test passes
  • bun run --cwd packages/cli test passes
  • Post-merge: verify cf-cache-status: HIT on deployed Pages

Summary by cubic

Edge-cache /api/registry/** at Cloudflare using Nitro routeRules so cache hits bypass the Pages Worker, reducing cost and speeding up repeated CLI registry lookups. Implements #34 with 5 min browser TTL and 1 h edge fresh + 24 h SWR.

  • New Features
    • Added apps/registry/app/route-rules.ts exporting REGISTRY_CACHE_CONTROL and registryApiRouteRules with cache-control: public, max-age=300, s-maxage=3600, stale-while-revalidate=86400.
    • Wired routeRules in apps/registry/nuxt.config.ts to enable edge caching for /api/registry/**.
    • Added apps/registry/test/nuxt-config.test.ts to assert the header and cache settings; added test script in apps/registry/package.json.
    • Moved track docs to .please/docs/tracks/completed/registry-edge-cache-20260408/ and updated .please/docs/tracks.jsonl.
    • Aligns with feat(registry): edge caching for /api/registry/** route #34 acceptance: AC-2 covered by tests; AC-4 verified via CLI tests; AC-1/AC-3 to be verified post-deploy.

Written for commit 3938282. Summary will update on new commits.

amondnet added 3 commits April 8, 2026 20:36
Set 5 min browser / 1 h edge fresh + 24 h SWR on the registry lookup
route so Cloudflare Pages bypasses the Worker on repeat CLI lookups.

Route rules are extracted to app/route-rules.ts so a bun test can
assert them without pulling in Nuxt's auto-import graph.

Refs #34
@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

Auto-approved: Isolated configuration change adding edge caching headers via Nitro routeRules with corresponding unit tests; very low risk of breakage and high performance benefit.

Architecture diagram
sequenceDiagram
    participant CLI as CLI / Browser
    participant CF as Cloudflare Edge (Cache API)
    participant Worker as Pages Worker (Nitro)
    participant Content as Nuxt Content (@nuxt/content)

    Note over CLI,Content: Registry API Request Flow (/api/registry/**)

    CLI->>CF: GET /api/registry/vercel/next.js
    
    alt NEW: Cache HIT (Within 1h s-maxage)
        CF-->>CLI: 200 OK (Served from Edge)
        Note right of CF: cf-cache-status: HIT<br/>Worker bypassed (Cost saved)
    
    else Cache MISS or STALE
        CF->>Worker: Forward Request
        
        Worker->>Worker: CHANGED: Apply routeRules
        Worker->>Content: Query registry markdown
        Content-->>Worker: Registry Data
        
        Worker->>Worker: NEW: Inject REGISTRY_CACHE_CONTROL
        Note right of Worker: public, max-age=300, s-maxage=3600, swr=86400
        
        Worker-->>CF: 200 OK + Cache Headers
        CF->>CF: Store in Edge Cache
        CF-->>CLI: 200 OK
        Note right of CF: cf-cache-status: MISS/DYNAMIC
    end

    opt NEW: Stale-While-Revalidate (Between 1h and 24h old)
        Note over CF,Worker: Background Revalidation
        CF-->>CLI: 200 OK (Stale Data)
        CF->>Worker: Async Fetch (Refresh Cache)
        Worker->>Content: Query latest markdown
        Content-->>Worker: Data
        Worker-->>CF: Updated Data
        CF->>CF: Update Cache (Fresh for next 1h)
    end
Loading

@amondnet amondnet self-assigned this Apr 8, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 8, 2026

Copy link
Copy Markdown

Deploying ask-registry with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3938282
Status:⚡️  Build in progress...

View logs

- Move track: active/ -> completed/
- Update status: in_progress -> review
- Link PR #36

Refs #34
@amondnet amondnet merged commit 1c9b7db into main Apr 8, 2026
4 of 5 checks passed

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 4 files (changes from recent commits).

Auto-approved: Implements edge caching via standard Nitro routeRules with automated tests. Low risk, performance-focused config change with no logic or security impact.

@amondnet amondnet deleted the amondnet/loud-blackberry branch April 8, 2026 11:53
This was referenced Apr 8, 2026
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.

feat(registry): edge caching for /api/registry/** route

1 participant