Cache not matching

Hey there, I already had quite some projects with Cloudflare workers (and caches). However, i encountered an issue with cache put and match from different endpoints.
- When matching in the same endpoint where the put happens i get a cache hit. Same when putting in the endpoint where match happens. - I tried a static URL/string (a subdomain of my worker domain) and still no match. - I tried to use a custom cache instead of caches.default without luck Does anyone has an idea of what could be the issue? This is a web-hook that is called from an external service. I want to cache prediction.output which is a URL of type string
const imageKey = encodeURIComponent(new URL(prediction.input.image_url).pathname);
const inputKey = encodeURIComponent(prediction.input.labels.toString());
const cacheKey = `${replicateURL}-${imageKey}-${inputKey}`;
console.log({ replicateURL, imageKey, inputKey });
console.log('cacheKey put', cacheKey);
const cacheResponse = new Response(prediction.output, {
headers: {
'Cache-Control': 'private, max-age=31536000',
'Content-Type': 'text/plain',
},
});
await caches.default.put(cacheKey, cacheResponse);
const imageKey = encodeURIComponent(new URL(prediction.input.image_url).pathname);
const inputKey = encodeURIComponent(prediction.input.labels.toString());
const cacheKey = `${replicateURL}-${imageKey}-${inputKey}`;
console.log({ replicateURL, imageKey, inputKey });
console.log('cacheKey put', cacheKey);
const cacheResponse = new Response(prediction.output, {
headers: {
'Cache-Control': 'private, max-age=31536000',
'Content-Type': 'text/plain',
},
});
await caches.default.put(cacheKey, cacheResponse);
This is the file where i try to match against my cache key
const imageKey = encodeURIComponent(new URL(input.image_url).pathname);
const inputKey = encodeURIComponent(input.labels.toString());
const cacheKey = `${replicateURL}-${imageKey}-${inputKey}`;
console.log({ replicateURL, imageKey, inputKey });
console.log('cacheKey match', cacheKey);

const response = await caches.default.match(cacheKey);

if (response) {
const url = await response.text();
console.log('Grounding-Sam cached');

ctx.waitUntil(imageAnalyticsAI(request, env, url));
} else {
//fetching from api
}
const imageKey = encodeURIComponent(new URL(input.image_url).pathname);
const inputKey = encodeURIComponent(input.labels.toString());
const cacheKey = `${replicateURL}-${imageKey}-${inputKey}`;
console.log({ replicateURL, imageKey, inputKey });
console.log('cacheKey match', cacheKey);

const response = await caches.default.match(cacheKey);

if (response) {
const url = await response.text();
console.log('Grounding-Sam cached');

ctx.waitUntil(imageAnalyticsAI(request, env, url));
} else {
//fetching from api
}
1 Reply
antim8
antim8OP4d ago
@Rebux
Want results from more Discord servers?
Add your server