Cloudflare selective purge confusion

Author
Diya Mehta Author
|
5 days ago Asked
|
13 Views
|
0 Replies
0

Hey everyone,

I'm a new SaaS founder and just launched my app, which has a fair bit of user-generated content. I'm trying to optimize our Cloudflare caching to make sure users always see the most up-to-date information, especially after they make an edit or create something new. Right now, I can do a full cache purge, but that's obviously too broad and impacts the entire site, which isn't ideal for user experience or performance.

My goal is to selectively purge specific content โ€“ like a single blog post, a profile page update, or a specific product listing โ€“ without touching the rest of the cache. Iโ€™ve been trying to use Cloudflareโ€™s API for this, specifically the "Purge Individual Files by URL" endpoint, but I'm running into issues where the content just isn't updating as expected on the frontend even after the API reports success. It feels like I'm missing a fundamental step or concept regarding proper cache invalidation for dynamic content.

Here's a simplified example of what I'm trying via a curl command, assuming a specific URL needs to be updated:

curl -X POST "https://api.cloudflare.com/client/v4/zones/{ZONE_ID}/purge_cache" \
     -H "X-Auth-Email: [email protected]" \
     -H "X-Auth-Key: {API_KEY}" \
     -H "Content-Type: application/json" \
     --data '{"files":["https://myawesomesaas.com/blog/my-updated-post"]}'

Even after getting a "success": true response, visiting https://myawesomesaas.com/blog/my-updated-post often shows the old version for several minutes. Am I using the wrong endpoint, or is there a specific header or setting I need to ensure Cloudflare properly invalidates and fetches the fresh content? What's the correct approach or best practice for implementing Cloudflare's selective purge for dynamic content via the API, especially for individual items?

0 Answers

No answers yet.

Be the first to provide a helpful answer!

Your Answer

You must Log In to post an answer and earn reputation.