buidl0
buidl0
CDCloudflare Developers
Created by buidl0 on 8/25/2023 in #workers-help
Cache API Expires After 120m
Hi guys, I have a worker that fetch from JSON from origin and supposed to cache it "permanently" in edge. Below is the sample code:
const originUrl = new URL(req.url);
originUrl.searchParams.append('t', Date.now().toString()); // Ensure Hitting Origin
const originRes = await fetch(originUrl.toString(), req);

// ... other checks to make sure origin response is 200.

originRes.headers.delete('Cache-Control');
originRes.headers.append('Cache-Control', 'public, max-age=31536000, immutable');

cache.put(cacheKey, originRes);
const originUrl = new URL(req.url);
originUrl.searchParams.append('t', Date.now().toString()); // Ensure Hitting Origin
const originRes = await fetch(originUrl.toString(), req);

// ... other checks to make sure origin response is 200.

originRes.headers.delete('Cache-Control');
originRes.headers.append('Cache-Control', 'public, max-age=31536000, immutable');

cache.put(cacheKey, originRes);
Cam confirm that the above code is cached in edge with CF-Cache-Status and Age of the subsequence response. The "Browser Cache TTL" of the zone is also configured to "Respect Existing Headers" and that the Cache-Control is the overwritten one with 1 year TTL in the worker. However, the cache will get deleted from edge as soon as it hit 7.2k Age, or 120m, which is the default edge TTL for code 200. Can I check if this is a limitation with Cache API or is there any other config that I missed out? Thank you.
4 replies