21 lines
559 B
TypeScript
21 lines
559 B
TypeScript
export function shouldCacheResponse(response: Response | null): boolean {
|
|
if (!response) {
|
|
return false;
|
|
}
|
|
|
|
const cacheControl = response.headers.get('Cache-Control') ?? '';
|
|
const pragma = response.headers.get('Pragma') ?? '';
|
|
const normalizedCacheControl = cacheControl.toLowerCase();
|
|
const normalizedPragma = pragma.toLowerCase();
|
|
|
|
if (normalizedCacheControl.includes('no-store') || normalizedCacheControl.includes('private')) {
|
|
return false;
|
|
}
|
|
|
|
if (normalizedPragma.includes('no-cache')) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|