A Next.js fetch wrapper for edge middleware that uses Vercel Runtime Cache as its caching backend. Current stable version is 0.8.2. It provides a drop-in replacement for the native fetch API, mimicking Next.js's Data Cache behavior in edge middleware where standard Data Cache is unavailable. Features include support for Next.js fetch options (cache, next.revalidate, next.tags), SWR (Stale-While-Revalidate) caching strategy via waitUntil(), automatic cache key generation including body for POST/PUT, GraphQL query caching, cache status headers, and graceful fallback. Requires @vercel/functions >=2.2.0 and next >=14.0.0 as peer dependencies, and Node >=18.0.0. Ships TypeScript types. The library addresses a known limitation of Next.js on Vercel (https://github.com/vercel/next.js/pull/80378) where fetch caching is not available in edge middleware.
npm install cached-middleware-fetch-nextNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of cachedFetch in Next.js middleware with revalidation, tags, and cache status headers.
Plan for cache invalidation on deployment. Use tags for selective revalidation via waitUntil.
Run 'npm install @vercel/functions' and ensure it's deployed with the application.
Omit the 'cache' option or use 'cache: 'force-cache'' only if overriding a global default.
For POST requests that change server state, do not use caching or set 'cache: 'no-store''.
Ensure your environment supports waitUntil() (Vercel Edge Functions do). Avoid using in environments where waitUntil is unsupported.
Ensure GraphQL request bodies are exactly identical for cache hits; include query and variables consistently.
npm install @vercel/functions
Replace 'import cachedFetch from ...' with 'import { cachedFetch } from ...'Provide a valid number (seconds) or false: { next: { revalidate: 60 } } or { next: { revalidate: false } }Upgrade Node to >=18.0.0 or ensure deployment on Vercel Edge Functions. Alternatively, avoid SWR options.