Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up Cloudflare purging when publishing/editing blog posts #146

Open
geerlingguy opened this issue Mar 19, 2022 · 5 comments
Open

Set up Cloudflare purging when publishing/editing blog posts #146

geerlingguy opened this issue Mar 19, 2022 · 5 comments
Labels

Comments

@geerlingguy
Copy link
Owner

Any time I publish or save an edit to a blog post, I'd like to automatically trigger a Cloudflare purge on the following paths:

  1. The blog post URL
  2. The home page (/)
  3. The blog page (/blog)

Might not always need to do the latter two, but it's safe enough to do anyways, IMO.

One thing to consider—the cache might still be stale in Nginx itself, since it's storing a 5-10 minute separate cache of everything. So one thing I could do is disable that cache since I'm routing everything through Cloudflare now. Maybe.

Related to #141.

@minecraftchest1
Copy link

I have been running a WordPress blog behind Cloudflare for a few days and made a few changes with Cloudflare set to provide a 4 hour cache time in both the cache page in the Cloudflare Dashboard, as well as with a page rule and it has always updated immediately for me. From that, I don't think that caching will be a problem for you. Granted, I haven't played with it very much and I am using WordPress, not Drupal so your results may very.

TLDR: I would check to see if caching is actually going to be an issue before trying to do automatic cache clearing.

@geerlingguy
Copy link
Owner Author

I have a 1 hour TTL set in Cloudflare, and it definitely respects that—I'd rather make sure the RSS feed and home page are updated immediately, so the Drupal module integrates with Cloudflare's API to purge by path, and that should hopefully be enough for me.

The one thing I need to look into is if I can get that API functionality on a free plan. Not sure if I'd need Pro or Enterprise to do that :/

I remember it being easier to set up with Varnish or Fastly (which uses Varnish IIRC).

@minecraftchest1
Copy link

I haven't had issues with using the api on the cloudflare free plan, but I haven't played with it much.

@userbradley
Copy link

The cloudflare free plan will be fine.

As long as you don't send more than 1200 requests per 5 minutes

I am looking at doing something similar for my site

I'll take a stab at this, and let you know how simple/ annoying it was

@geerlingguy
Copy link
Owner Author

geerlingguy commented Oct 31, 2022

For now I've actually set this up using an Ansible playbook, since the purge also has to happen after Nginx static cache is cleared, and I'd rather not do all that through Drupal/PHP.

See my blog post on how I set it up: Clearing Cloudflare and Nginx caches with Ansible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants