Accessing Cache API Typescript
In the cache API documentation (https://developers.cloudflare.com/workers/runtime-apis/cache/#accessing-cache), it says to access the cache via a global variable. However the examples show a third parameter in the fetch method. This parameter doesn't exist in my Typescript definition that wrangler generated.
Which is the correct way to access the Cache API? Also if I use the Cache API should I disable edge caching via page rules for the route?
Cache · Cloudflare Workers docs
The Cache API allows fine grained control of reading and writing from the Cloudflare global network cache.
8 Replies
With functions it should look something like
why do these examples have a third parameter?
https://developers.cloudflare.com/workers/examples/cache-api/
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 …
my typescript definition doesn't show a third argument nor an object?
There are more parameters on the context https://developers.cloudflare.com/pages/platform/functions/api-reference/#eventcontext and I just made it simpler. The docs you link are workers and not functions through
Ah my bad I meant workers. For workers would i access it via the global variable?
I think you could make
const cache = cache.default
as a global variable or you can have it for each request.Got it. Is the doc I linked outdated then?
I don't think so. Unfortunately my knowledge of typescript types is very limited but it is a global object not a global variable.