Cache isn't always hit

Following the example at https://developers.cloudflare.com/workers/examples/cache-api/ we implemented the Cache API on our Pages Function. Few changes were made, for example instead of s-maxage, Expires was used. The endpoint that uses the cache is only accessed by our app not web browsers. When looking at the console logs we figured that not every request hits the cache, it's roughly about a 50% hit rate. Is this the expected behavior or can the hit rate be improved somehow?
Using the Cache API · Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment existing ones …
2 Replies
Chaika
Chaika8mo ago
In general, more requests, more your item will be in cache. The Cache API is just the local cloudflare location (colo) cache. Cloudflare has some 350 or so locations/points of presence, identified by airport codes (ex: ORD), and each location may have mutiple datacenters/colos within, all with their own cache. Somewhere around ~500 colos, and thus, ~500 seperate caches. Your app makes the request from the users device? If so, sounds like your users might just be a bit spread out/infrequently accessing the same cached object Could try increasing cache ttl/expires if you can as well
Samantas5855
Samantas58558mo ago
Hi, the requests are indeed made from the user's device. Our users can be from all around the world, but the majority is from two countries. The endpoint is being hit many times a second (about 3 to 5 times on average). The Expires value cannot be increased since it isn't static, it's dynamic and depends on other factors. It's usually 10 minutes on average