UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

38 lines (37 loc) • 1.12 kB
/** * Generate default cache response headers from CacheOptions. * Used when the provider doesn't supply its own `setHeaders()`. */ export function defaultSetHeaders(options) { const headers = new Headers(); // CDN-Cache-Control const directives = []; if (options.maxAge !== undefined) { directives.push(`max-age=${options.maxAge}`); } if (options.swr !== undefined) { directives.push(`stale-while-revalidate=${options.swr}`); } if (directives.length > 0) { headers.set("CDN-Cache-Control", directives.join(", ")); } // Cache-Tag if (options.tags && options.tags.length > 0) { headers.set("Cache-Tag", options.tags.join(", ")); } // Last-Modified if (options.lastModified) { headers.set("Last-Modified", options.lastModified.toUTCString()); } // ETag if (options.etag) { headers.set("ETag", options.etag); } return headers; } export function isCacheHint(value) { return value != null && typeof value === "object" && "tags" in value; } export function isLiveDataEntry(value) { return value != null && typeof value === "object" && "id" in value && "data" in value && "cacheHint" in value; }