AI summary by TwinMind

I found "use cache" BEFORE it dropped

Theo - t3․gg

29m 48s

Background and Context

  • Next.js team has been unusually quiet since last Next.js conference
  • Speaker no longer has formal relationship with Vercel, allowing independent analysis
  • Current Next.js caching system is problematic with too many layers and insufficient insight
  • Multiple caching layers: React cache, Next unstable cache, headers caching, database/Redis/KV solutions

Use Cache Feature Discovery

  • Lee Robinson accidentally showed use cache feature during live stream
  • Feature described as "unstable cache on steroids" but "super experimental, super early"
  • Speaker reverse engineered the feature through GitHub release tabs and canary builds
  • Found references to Dynamic IO, use cache in route handlers, cache as string support

Async/Await as Dynamic Indicator

  • Next.js now uses await keyword to determine what's dynamic vs static
  • Previously required explicit dynamic markers like export const dynamic = 'force-dynamic'
  • Async request APIs (cookies, headers) now require await even though data is immediately available
  • await acts as compiler hint that function/component is dynamic
  • Components without async calls default to static rendering

Use Cache Functionality

  • use cache effectively cancels out async dynamic behavior
  • Allows opting specific functions out of dynamic rendering while keeping others dynamic
  • Can be applied to individual async functions or entire components
  • Works through "function painting" - if all awaited calls are use cache tagged, entire route can be cached
  • Enables granular control over what gets cached vs rendered dynamically

Cache Configuration and Lifecycle

  • cacheTag function for tagging cached values for selective invalidation
  • cacheLife function with configuration object:
    • stale: how long client can keep old value without checking server
    • revalidate: how long server holds cached value
    • expire: maximum staleness before forcing fresh generation
  • Stale-while-revalidate behavior: old values served while revalidating in background
  • Cache life profiles can be defined in config and referenced by name (e.g., "frequent")

Error Handling and Validation

  • Cannot use cookies/headers inside use cache functions (would cache user-specific data globally)
  • Compiler detects and prevents these anti-patterns
  • Better error detection compared to unstable cache wrapper
  • Build-time and runtime validation for cache misuse

Practical Implementation Testing

  • Speaker built working demo with World Time API
  • Demonstrated caching at different levels (component vs function)
  • Showed cache invalidation timing with 10-second revalidate, 30-second expire
  • Proved granular caching works - can cache slow operations while keeping other parts dynamic
  • API routes support use cache functionality

Technical Limitations and Behavior

  • Server-only feature, doesn't work on client components
  • Client components cannot define inline use cache functions
  • Can work with server actions called from client components via API endpoints
  • SWR behavior may not be fully implemented in development/self-hosted environments
  • Default cache life profile must be provided in configuration

Developer Experience Improvements

  • Eliminates need to think about caching during function authoring
  • Add caching when performance optimization needed
  • Much simpler than unstable cache with complex key management
  • Better fits development workflow compared to current caching solutions
  • Potential for improved dev tools and debugging experience

TwinMind

Get summaries like this for your own meetings

TwinMind takes notes in the background during meetings, lectures, and calls, then writes the summary for you.

Free plan to get started

No bot joins your calls

Phone, desktop & Chrome apps

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome