eminos/statamic-cloudflare-cache
A Statamic addon that automatically purges Cloudflare cache when content changes, keeping your site fast and up to date while reducing stale pages after edits in the control panel.
This is a Statamic addon (not a plain Laravel package), so install it in the Statamic site that sits behind Cloudflare.
composer require eminos/statamic-cloudflare-cache
php artisan vendor:publish --tag=statamic-cloudflare-cache-config
Then set credentials in .env — a scoped Cloudflare API token (permission: Zone → Cache Purge, optionally Zone → Zone Read) plus the zone ID:
CLOUDFLARE_API_TOKEN=...
CLOUDFLARE_ZONE_ID=...
First things to read, in order:
config/statamic-cloudflare-cache.php — the published config is the real documentation. Look for the enabled/disabled toggle, the event or collection allow-list, and the purge strategy (everything vs. URLs).php artisan list filtered for the addon's namespace, to find any manual purge command for smoke-testing.First use case: make sure the config cache is clear (php artisan config:clear), save and publish a single entry in the CP, then confirm the purge in the Cloudflare dashboard (Caching → Configuration → Purge Cache history, or the audit log). If nothing happens, temporarily set APP_ENV=local aside and check the addon's enabled flag — most failures at this stage are "addon disabled outside production" or a token missing Cache Purge scope.
Event-driven purge as the default. The addon listens to Statamic's save/publish/delete lifecycle and invalidates Cloudflare for you. The normal pattern is: install, configure, forget. Don't call the Cloudflare API yourself in Entry::saved listeners unless you're deliberately bypassing the addon.
Targeted purges via static cache invalidation (v1.5.0+). The new release wires the addon into Statamic's static-cache invalidation so purges can be scoped to the specific URLs that changed instead of nuking the whole zone. Enable it when you have static caching on; the practical pattern is:
Choose a strategy per environment. Full-zone purge is simplest and most correct; targeted purge is faster to propagate and much gentler on origin. Typical setup: targeted purge in production, full purge (or no purge) in staging, disabled locally.
Queue it. Purges are outbound HTTP calls inside a request that's already doing a save. If your editors save often or you run imports, push the purge onto a queue (QUEUE_CONNECTION=redis) so CP saves stay snappy and you don't hit Cloudflare rate limits.
Programmatic purges. For things Statamic doesn't know about — deploys, asset changes, taxonomy term edits if not covered — wrap the purge in your own deploy hook or Artisan command and run it as the last step of the pipeline. Never purge before the new code is live, or you'll re-cache the old HTML.
Multi-site / multi-domain. Each site resolves to a different hostname; make sure the config maps site → base URL correctly, otherwise you purge example.com/about when the cached copy is example.de/about. Verify per-site after any domain change.
Guard rails. Explicitly disable the addon in local/testing, and skip purges for drafts, revisions, and imports unless you want them. Bulk content migrations are the classic way to burn through your API quota.
.env, run php artisan config:clear. In production with config:cache, a changed CLOUDFLARE_ZONE_ID that never takes effect is almost always this.curl -I against the origin and against the edge before blaming the addon./api/ JSON endpoints, or sitemap URLs alongside the page).How can I help you explore Laravel packages today?