Skip to content

MacareuxDigital/addon_cdn_cache_purge_cloudflare

Repository files navigation

CDN Cache Purge for Cloudflare

This is Concrete CMS add-on to purge Cloudflare cache as well as Concrete CMS cache.

It saves time from logging into Cloudflare dashboard to clear Cloudflare cache. You only need to visit Concrete CMS dashboard to press button to clear cache altogether.

Requirement

  • Concrete CMS v8.0 and later
    • tested with Concrete CMS V8.5.12 and later
  • Tested with PHP 7.4
  • Cloudflare
    • Auth Key
    • Auth Email
    • Zone ID

How to Set up

First, you get API keys from Cloudflare, then install the add-on, save the API key.

Obtain Cloudflare Zone ID

  • Login to Cloudflare dashboard
  • Click your website domain
  • Visit overview page
  • Locate API in the sidebar
  • You find Zone ID. Save it

Generate Cloudflare Auth Key

  • Visit My Profile page
  • Find & visit API Tokens page
  • Click Create Token button
  • Find Create Custom Token at the bottom of the list and click Get started
  • Create Custom Token
    • Name your token accodingly (e.g, example.com cache clear)
    • In Permissions
      • Select Zone in the 1st box
      • Select Cache Purge in the 2nd box
      • Select Purge in the last box
    • Zone Resources
      • Select Include
      • Select Specific Zone, then select your domain.
    • Client IP Filtering
      • If your web server has specific public IP address, you can set it to enfource the security of your API key
    • Click Continue to summary
  • Check the API key summary then click Create Token
  • Make a note of your API tokens, YOU WILL NEVER BE able to get it again!

What is Your Cloudflare Auth Email

  • Auth email is the email address that you signed in to Cloudflare to create the API key.

Install This Add-on

  • Upload the folder cdn_cache_purge_cloudflare under packages folder of your Concrete CMS
  • Install the package
    • via Dashboard
    • via CLI
      • V8 and earlier concrete/bin/concrete5 c5:package:install cdn_cache_purge_cloudflare
      • V9 and later concrete/bin/concrete c5:package:install cdn_cache_purge_cloudflare

Save API keys

  • Visit [Dashboard] -> [System and Setting] -> [Optimization]
  • Visit Cloudflare page
    • URL: [Your Site]/index.php/dashboard/system/optimization/cloudflare/
  • Enter Cloudflare Auth Key, Cloudflare Auth Email and Cloudflare Zone ID
  • Click Save

Clear cache from Concrete CMS

  • Visit [Dashboard] -> [Optimization] -> [Clear Cache] page
    • URL: [Your site]/index.php/dashboard/system/optimization/clearcache/
  • Press clear cache
  • You can visit [Dashbord] -> [Reports] -> [Logs]
    • URL: [Your Site]/index.php/dashboard/reports/logs/
    • Cache purge log will be saved at NOTICE level. You can check the result with ID.

Debug mode (Troubleshooting)

If you switch the logging level to Debug, this add-on will also save the actual API call.

It is great way to troubleshoot when having issue clearing the cache.

Log level setting page is located at [System and Settings] -> [Environment] -> [Logging Settings]. [Your Site]/index.php/dashboard/system/environment/logging/

WARNING: It will also save API key in the log. You MUST make sure to clear the log after testing.

Technical description

  • This add-on hooks Concrete CMS's on_cache_flush event.
  • When Concrete CMS receives to clear cache, it will send a simple API call to Cloudflare to clear the cache of specified zone.
  • Config text will be saved at application/config/generated_overrides/cdn_cache_purge_cloudflare/cloudflare.php

Version History

Version Date Note
0.9.2 Dec 24, 2023 Initial public release of this add-on.

Credit

  • Katz Ueno (@katzueno), Macareux Digital, Inc.
  • Hishikawa Takuro (@HissyNC), Macareux Digital, Inc.
  • Icon was generated by Cloudflare AI using stable-diffusion-xl-base-1.0 model

About

Concrete CMS add-on to purge cache of Cloudflare zone

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages