feat: browsers revalidate route-cached pages; document the site cache purge
- privateRevalidate sets max-age=0 on cache-control values with s-maxage - server/plugins/journal-revalidate.ts wraps res.setHeader per request, so Nitro's 200 and h3's 304 answers both carry it - purge-check: max-age=0 on 200 and 304, purged _payload.json, a second purge after re-caching, X-Real-IP refused, 404 on a server without a token - README: cachePurgeToken row and a Site cache purge section
This commit is contained in:
@@ -83,3 +83,18 @@ export function parsePurgeEvent(body: unknown): PurgeEvent {
|
||||
const slug = typeof raw.slug === 'string' ? raw.slug.replace(/[\u0000-\u001f\u007f-\u009f]/g, '').slice(0, MAX_SLUG_LENGTH) : ''
|
||||
return { kind, slug }
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes browsers revalidate a shared-cache response: for a cache-control
|
||||
* value that carries s-maxage it sets max-age=0, replacing any max-age=<n>
|
||||
* or prepending it, and keeps every other directive (shared caches keep
|
||||
* s-maxage). Other values, such as a static asset's
|
||||
* "public, max-age=31536000, immutable", are returned unchanged.
|
||||
*/
|
||||
export function privateRevalidate(cacheControl: string): string {
|
||||
if (typeof cacheControl !== 'string' || !/(^|[\s,])s-maxage\s*=/i.test(cacheControl)) return cacheControl
|
||||
if (/(^|[\s,])max-age\s*=\s*\d*/i.test(cacheControl)) {
|
||||
return cacheControl.replace(/(^|[\s,])max-age\s*=\s*\d*/i, '$1max-age=0')
|
||||
}
|
||||
return `max-age=0, ${cacheControl}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user