justbetter/statamic-cloudflare-purge
| Install | |
|---|---|
composer require justbetter/statamic-cloudflare-purge |
|
| Latest Version: | 2.2.0 |
| PHP: | ^8.4 |
| License: | MIT |
| Last Updated: | Jul 28, 2026 |
| Links: | GitHub · Packagist |
Statamic Cloudflare Purge
This addon will hook into your already existing statamic invalidation and purge any pages that have been invalidated from your Cloudflare cache.
Requirements
- PHP ^8.4
- Laravel ^12.40 or ^13.0
- Statamic ^6.0
Installation
composer require justbetter/statamic-cloudflare-purge
Usage
You need a Cloudflare API key with the Zone.Cache Purge permission, and set it in your .env:
CLOUDFLARE_API_TOKEN="token_here"
You will also have to define the zone of your website:
CLOUDFLARE_ZONE="zone_id_here"
Finally, enable the package:
CLOUDFLARE_PURGING_ENABLED=true
If you have a multistore setup with multiple zones, see the Configuration section.
This package listens to the UrlInvalidated event and adds every invalidated URL to a temp file. It also listens to certain events as defined in the config file to flush the whole cache.
Then, when you run the statamic:cloudflare:purge command or the PurgeCloudflareCachesJob job, these files will get purged from the Cloudflare cache. As such, you should add this to your routes/console.php like so:
Schedule::job(\JustBetter\StatamicCloudflarePurge\Jobs\PurgeCloudflareCachesJob::class)->everyFiveSeconds()->withoutOverlapping();
[!NOTE] Be aware of the rate limits on the API. This package handles single-request limits automatically, but it does not take into account the per-account limits. You're probably not going to run into any issues, but it's possible. Especially if you end up calling an everything-purge often and you're on a free plan, or have a lot of sites running on the same Cloudflare account.
Configuration
You can publish the config with the following command:
php artisan vendor:publish --provider="JustBetter\StatamicCloudflarePurge\StatamicCloudflarePurgeServiceProvider"
Multiple zones
Using the configuration file you can define multiple zones. There are 3 ways of defining the zone in your config:
// Single zone
'zone' => 'zone_id',
// Multiple zones based on statamic site handles
'zone' => [
'default' => 'zone_id_default',
'french' => 'zone_id_french',
...
],
// Complete freedom with a callback
'zone' => function() {
return \App\Facades\Custom::getCloudflareZone()
},
Cache flushing
You can define any events that will trigger a full cache purge immediately in the config file. By default, these three events have been defined for this purpose:
'flush-events' => [
\Statamic\Events\GlobalSetSaved::class,
\Statamic\Events\NavSaved::class,
\Statamic\Events\StaticCacheCleared::class,
],
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Related Packages
A Redis based, automated and scalable database caching layer for Laravel
This package allows you to cache your routes definitions, thereby speeding up ea...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 2.2.0 | ^8.4 | ^12.40| | MIT | |
| 2.1.0 | ^8.4 | MIT | ||
| 2.0.0 | ^8.3 | MIT | ||
| 1.0.1 | ^8.1 | MIT | ||
| 1.0.0 | ^8.1 | MIT |