Cloudflare overzealously caching

I’ve recently created a ‘blog’ which you can see here Travel The Globe. There’s two posts, when you got a post a route sends you to a cloudflare worker which retrieves post data from workers kv and returns html for the post itself. Problem is if you go to the news page, click on one of the articles and then go back and click on a different one despite the url it will have the content of the first blog post instead of the second.

Long story short:
Going to Travel The Globe shows the ssr-and-testing-suite article

Going to Travel The Globe immedietly after shows the srr-and-testing-suite article again, no matter if you have cache disabled or reload and will only change to the right post after ~5-10 minutes.

Create a custom Page Rule with the lowest Cache Level.

1 Like

I’ve done this but it doesn’t seem to help. Should I be using Edge Cache TTL and browser cache TTL because the lowest settings for those are 2 hours and 30 minutes respectively.

Interestingly enough giving it an invalid link like here: Travel The Globe correctly returns an error response. Is it possible workers KV is caching and returning the wrong things?


Not sure if you’ll ever see this but I’d like to say thank you so much @thomas4 I wasn’t being the most polite and you graciously gave your time to help me, Indeed my problem was that I was using a template for my HTML (const string HTML) and ‘duplicating’ that and using string interpolation to swap in blog values but the duplicate existed in global scope by accident and was presisting between sessions. Again thank you for your generousness :heart:

KV doesn’t cache other values, this is a code issue.

Please make sure that you’re not storing the data in a global variable, make sure you clear variables of pervious data when the function is executed.

A global looks like this:

let MyObj;

async function handleRequest(request) {
MyObj = myKV.get('keyname', 'json');

Since the value is assigned to the global scope, it will persist between pageloads.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.