Openstatus www.openstatus.dev
at 4c0f4c00a38753a5d0dfd7e7b7b7706dec6f1503 26 lines 1.5 kB view raw
1interface CfCacheStatusInfo { 2 description: string; 3 value: string; 4} 5 6export function parseCfCacheStatus(header: string): CfCacheStatusInfo { 7 const description = getCacheDescription(header); 8 return { description, value: header }; 9} 10 11function getCacheDescription(key: string): string { 12 switch (key.toUpperCase()) { 13 case "HIT": 14 return "Your resource was found in Cloudflare’s cache. This means that it has been previously accessed from your original server and loaded into Cache. It has not expired."; 15 case "MISS": 16 return "Cloudflare looked for your resource in cache but did not find it. Cloudflare went back to your origin server to retrieve the resource. The next time this resource is accessed its status should be HIT."; 17 case "BYPASS": 18 return "Cloudflare has been instructed to not cache this asset. It has been served directly from the origin. This is usually because something like an existing NO-CACHE header is being respected."; 19 case "EXPIRED": 20 return "Cloudflare has previously retrieved this resource, but its cache has expired. Cloudflare will go back to the origin to retrieve this resource again. The next time this resource is accessed its status should be HIT."; 21 case "DYNAMIC": 22 return "This resource is not cached by default and there are no explicit settings configured to cache it. You will see this frequently when Cloudflare is handling a POST request. This request will always go to the origin."; 23 default: 24 return "-"; 25 } 26}