Does it happen if you run it locally with wrangler?
Does it happen if you run it locally with wrangler?

fetch to a URL outside of my zone, polish is used...?package.json file. The main thing you care about is:scripts. In my case I use bun as why not. No need for pnpm workspace as this works the same if not better.bun main-site install or bun install depends on what you want to do.scripts in package.json so you can do something like bun main-site deploy or bun mail-worker devpackage.json and let bun to handle the rest.wrangler.toml storage bindingsi couldnt get it to work, i would get cache miss everytimeThe Cache API doesn't work/will always return miss in a bunch of environments, including dev
However, any Cache API operations in the Cloudflare Workers dashboard editor, Playground previews, and any *.workers.dev deployments will have no impact. For Workers fronted by Cloudflare Accesshttps://developers.cloudflare.com/workers/runtime-apis/cache/
, the Cache API is not currently available. Only Workers deployed to custom domains have access to functional cache operations.
cacheKey for both cache.match and cache.put. however it was always a missRequest constructed from request.url has to be the cache key...
"type": "module",
"workspaces": [
"projects/*"
],
"scripts": {
"stripe-worker": "cd projects/stripe-worker && bun",
"main-site": "cd projects/main-site && bun",
"mail-worker": "cd projects/mail-worker && bun"
},
...cacheKeycache.matchrequest.urlapp.use("*", async (c, next) => {
const t = performance.now();
const cache = caches.default;
const cacheUrl = new URL(c.req.url);
const cacheKey = new Request(cacheUrl.toString(), c.req);
let response = await cache.match(cacheKey);
if (response) {
c.env.myData = { cachedData: await response.json() };
console.log("cache hit", performance.now() - t);
return next();
}
const object = await c.env.MY_R2_STORAGE.get("some-data.json");
if (!object) {
throw new Error("Data not found");
}
const headers = new Headers();
object.writeHttpMetadata(headers);
headers.set("etag", object.httpEtag);
const status = object.body ? 200 : 304;
const [body1, body2] = object.body.tee();
response = new Response(body1, {
headers,
status,
});
response.headers.append("Cache-Control", "s-maxage=31536000");
c.executionCtx.waitUntil(cache.put(cacheKey, response));
if (!cachedData) {
throw new Error("Data not found");
}
c.env.myData = { cachedData: await streamToJson(body2) };
console.log("cache miss", performance.now() - t);
return next();
});