Automatically purge your Cloudflare cache when content is rebuilt, ensuring visitors always see the latest version of your site.
- Automatic cache purge — Clears Cloudflare cache whenever the content index is rebuilt
- CLI commands — Manual purge and status check from the command line
- Admin integration — Status page and manual purge button in the admin dashboard
- Logging — All purge operations are logged to
storage/logs/cloudflare.log
- Create a Cloudflare API Token
- Add configuration to
app/config/ava.php:
'cloudflare' => [
'enabled' => true,
'zone_id' => 'your-zone-id-here',
'api_token' => 'your-api-token-here',
],- Test your setup:
./ava cloudflare:status
./ava cloudflare:purgeCloudflare API Tokens provide scoped access to specific resources. For this plugin, you need a token with Cache Purge permission.
-
Log in to the Cloudflare Dashboard
-
Click your profile icon (top right) → My Profile
-
Select API Tokens from the left sidebar
-
Click Create Token
-
Find "Edit zone cache" template and click Use template
This template includes the
Cache Purgepermission needed by this plugin. -
Under Zone Resources, select:
- Include → Specific zone → Your domain
-
(Optional) Add a Client IP Address Filtering for extra security:
- Add your server's IP address to restrict where the token can be used
-
Click Continue to summary → Create Token
-
Copy the token immediately — it won't be shown again!
If you prefer to create a custom token instead of using the template:
| Permission | Access |
|---|---|
| Zone → Cache Purge | Edit |
- Log in to the Cloudflare Dashboard
- Select your domain
- On the Overview page, scroll down the right sidebar
- Find Zone ID and copy it
./ava cloudflare:statusShows whether the integration is configured and active.
./ava cloudflare:purgeManually purge all cached content from Cloudflare. This is the same operation that runs automatically on rebuild.
When enabled, the plugin hooks into indexer.rebuild and purges the cache whenever:
- You run
./ava rebuild - You click "Rebuild Index" in the admin dashboard
- Auto-rebuild triggers (when
content_index.modeisauto)
For maximum performance with Ava, configure Cloudflare to cache your entire site. Since Ava purges the cache on every rebuild, you don't need to worry about stale content.
In Cloudflare Dashboard → Caching → Cache Rules, create a rule:
| Setting | Value |
|---|---|
| Rule name | Cache Everything |
| When | Hostname equals yourdomain.com |
| Then | Eligible for cache, Cache TTL: 1 year |
| Edge TTL | 1 year (or maximum allowed) |
| Browser TTL | Respect Existing Headers (or 1 day) |
If you prefer Page Rules (legacy feature):
- Go to Rules → Page Rules
- Create a rule for
yourdomain.com/* - Set Cache Level to Cache Everything
- Set Edge Cache TTL to the maximum (1 month or 1 year)
- Set Browser Cache TTL to a reasonable value (1 day recommended)
By default, Cloudflare only caches static assets (images, CSS, JS). The "Cache Everything" setting tells Cloudflare to also cache HTML pages. Combined with this plugin's automatic purge on rebuild, you get:
- ⚡ Faster load times — HTML served from Cloudflare's edge
- 🌍 Global CDN — Content served from the nearest data center
- 💰 Reduced origin load — Fewer requests hit your server
- 🔄 Always fresh — Cache purged automatically when you publish
If you have pages that shouldn't be cached (like /admin/* or /api/*), add a Cache Rule with higher priority:
| Setting | Value |
|---|---|
| When | URI Path starts with /admin |
| Then | Bypass cache |
- Verify the token was copied correctly (no extra spaces)
- Check the token hasn't expired
- Ensure the token has Cache Purge permission for your zone
- Verify the Zone ID is correct
- Ensure the API token has access to this specific zone
- Check browser cache (try hard refresh: Ctrl+Shift+R / Cmd+Shift+R)
- Verify Cloudflare is actually proxying your domain (orange cloud icon in DNS)
- Check if you have Browser Cache TTL set too high
./ava logs:tail cloudflare- Use scoped tokens — Only grant Cache Purge permission, nothing more
- Restrict by zone — Token should only access your specific domain
- IP filtering — If possible, restrict token to your server's IP
- Rotate regularly — Create new tokens periodically and revoke old ones
- Never commit tokens — Keep
ava.phpout of version control or use environment variables:
'cloudflare' => [
'enabled' => true,
'zone_id' => getenv('CLOUDFLARE_ZONE_ID'),
'api_token' => getenv('CLOUDFLARE_API_TOKEN'),
],This plugin is part of Ava CMS and is released under the same GPLv3 license.
Cloudflare® is a registered trademark of Cloudflare, Inc. This plugin is not affiliated with or endorsed by Cloudflare, Inc.