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.
3 Replies
Hello, I’m Allie!
The Edge Cache works on a best effort system. You are never guaranteed to have a value cached as long as you want it, especially not as long as a year. I wouldn’t expect an asset to last more than a day(unless it is very heavily requested).
buidl0
buidl010mo ago
Thank you. Thought that it was something wrong with my setup.
Codename_404
Codename_40410mo ago
So caching with cache api clears unused caches automatically? I thought I would have to manually track the requests