Download the PHP package eminos/statamic-cloudflare-cache without Composer
On this page you can find all versions of the php package eminos/statamic-cloudflare-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eminos/statamic-cloudflare-cache
More information about eminos/statamic-cloudflare-cache
Files in eminos/statamic-cloudflare-cache
Package statamic-cloudflare-cache
Short Description Cloudflare cache integration for Statamic
License MIT
Informations about the package statamic-cloudflare-cache
Statamic Cloudflare Cache
Automatically purge your Cloudflare cache when content changes in Statamic.
Features
- Automatically purges Cloudflare cache when Statamic content changes.
- Multi-zone support for Statamic multisite installations with different domains.
- Configurable events that trigger cache purging.
- Optional support for Statamic
static_cachinginvalidation rules viaUrlInvalidated/StaticCacheClearedevents. - Optional queuing of purge jobs for background processing.
- CLI command for manual cache purging.
- Simple configuration with backward compatibility.
Installation
You can install the package via composer:
Publish the config file:
Configuration
Basic Setup (Single Zone)
Add the following environment variables to your .env file:
Multi-Zone Setup (Multisite)
For Statamic multisite installations with multiple domains, you can configure multiple Cloudflare zones. The package uses a single API token for all zones.
In your config/cloudflare-cache.php file, add your zone mappings:
The package will automatically detect which zone to use based on the URL being purged. It will:
- First try to match the exact domain from the URL
- Then try without 'www.' prefix (so 'example.com' will match 'www.example.com')
- Fall back to the default
zone_idif no match is found
Getting Your Cloudflare Credentials
You can get your API token and Zone IDs from the Cloudflare dashboard:
-
API Token: Log in to your Cloudflare dashboard, go to "My Profile" > "API Tokens" and create a token with the "Zone.Cache Purge" permission for all zones you want to manage.
- Zone ID: Go to your domain's overview page in Cloudflare. The Zone ID is displayed in the right sidebar under "API" section.
Usage
Automatic Cache Purging
Once configured, the addon will automatically purge the Cloudflare cache when content changes in Statamic. By default, it listens for the following events:
- Entry saved/deleted
- Term saved/deleted
- Asset saved/deleted
- Global set saved/deleted (purges everything via
purge_everything_fallback)
You can configure which events trigger cache purging in the config file.
Event handling modes (either/or)
- Default (
use_statamic_static_cache_invalidation = false): uses this addon’s own content events (entry_*,term_*,asset_*, etc.). - Statamic static cache mode (
use_statamic_static_cache_invalidation = true): uses Statamic Static Cache events (url_invalidated,static_cache_cleared) and skips the addon’s legacy content events.
Queued Purging
If you prefer to handle cache purging in the background to avoid potential delays during web requests, you can enable queued purging. Set the CLOUDFLARE_CACHE_QUEUE_PURGE environment variable to true or set 'queue_purge' => true in the configuration file.
When enabled, purge operations triggered by events will be dispatched as jobs to your application's queue. Note: This requires you to have a queue worker running (php artisan queue:work).
Manual Cache Purging
You can manually purge the cache using the following command:
Advanced Configuration
The published configuration file (config/cloudflare-cache.php) allows you to customize the behavior of the addon:
Testing
License
The MIT License (MIT). Please see License File for more information.