Skip to main content
vinext implements Incremental Static Regeneration (ISR) and caching using a pluggable architecture. The default in-memory cache works out of the box, and you can swap in production backends like Cloudflare KV, Redis, or DynamoDB.

Cache Architecture

vinext’s caching system has two layers:
1

CacheHandler (Storage Layer)

A pluggable key-value store matching Next.js 16’s CacheHandler interface. Handles get/set operations with metadata.
2

ISR Layer (Semantics)

Sits above the CacheHandler and implements stale-while-revalidate, background regeneration, and tag-based invalidation.

CacheHandler Interface

The CacheHandler is a simple key-value store:
packages/vinext/src/shims/cache.ts

ISR Layer Implementation

The ISR layer wraps the CacheHandler:
packages/vinext/src/server/isr-cache.ts

Stale-While-Revalidate

ISR returns stale content immediately while regenerating in the background:

Deduplication

Multiple concurrent requests for the same stale key only trigger one regeneration:
packages/vinext/src/server/isr-cache.ts
This prevents “thundering herd” — a spike in traffic to a stale page only renders it once.

Pages Router ISR

Enable ISR by returning revalidate from getStaticProps:
pages/blog/[slug].tsx

Fallback Modes

With fallback: 'blocking':
  1. Request /posts/2 (not pre-rendered)
  2. vinext renders the page on-demand
  3. Caches the result with revalidate TTL
  4. Future requests serve from cache with stale-while-revalidate

App Router ISR

Enable ISR with route segment config:
app/blog/[slug]/page.tsx

Dynamic Rendering

Control when pages render:
app/dashboard/page.tsx

Tag-Based Revalidation

Invalidate cache entries by tag:
app/posts/[id]/page.tsx
Invalidate when data changes:
app/actions.ts

Path-Based Revalidation

"use cache" Directive

Next.js 16 introduced "use cache" for granular caching:

Function-Level Caching

app/components/RecentPosts.tsx

File-Level Caching

app/lib/posts.ts

Cache Profiles

Define reusable cache durations:
next.config.js

Cloudflare KV Cache Handler

For production on Cloudflare Workers, use the KV cache handler:
worker/index.ts

Binding KV Namespace

Add to wrangler.jsonc:
wrangler.jsonc
Create the namespace:

KV Implementation

packages/vinext/src/cloudflare/kv-cache-handler.ts

Custom Cache Handlers

Implement the CacheHandler interface for other backends:
lib/redis-cache.ts
Register it:

Cache Key Generation

vinext generates cache keys from the router type and pathname:
packages/vinext/src/server/isr-cache.ts
Examples:
  • pages:/ → root page
  • pages:/blog/hello-world → blog post
  • app:/dashboard/analytics → app route
  • app:__hash:a3f2b91c → long pathname (hashed)

Next Steps

Deployment

Deploy to Cloudflare Workers with KV cache

Server Components

Learn about RSC rendering

Server Actions

Mutate data and revalidate cache

Architecture

Understand vinext’s architecture