Files
vercel__next.js/test/e2e/app-dir/use-cache/pages/api/revalidate.ts
conico974 00d3c8307d Revalidate "use cache" caches during on-demand revalidation (#76100)
### What?
When doing an On Demand revalidation (with `res.revalidate` or using
`x-prerender-revalidate` header ), `use cache` entry will never get
revalidated

### Why?
It should behave the same as the fetch cache or `unstable_cache`

### How?

We force revalidation of `use cache` entry when doing an on demand
revalidation

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
2025-02-17 18:13:07 +01:00

23 lines
579 B
TypeScript

import type { NextApiRequest, NextApiResponse } from 'next'
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const pathParam = req.query['path']
if (!pathParam) {
return res.status(400).send(`Missing required query param "path"`)
}
const paths = Array.isArray(pathParam) ? pathParam : [pathParam]
try {
await Promise.all(paths.map((path) => res.revalidate(path)))
return res.json({ revalidated: true })
} catch (err) {
console.error(err)
return res.status(500).send(`Error revalidating ${paths}`)
}
}