springtimesoft / silverstripe-cloudflare-assets-purge
Queues a Cloudflare cache purge when Silverstripe assets are published, unpublished, or deleted
Package info
github.com/springtimesoft/silverstripe-cloudflare-assets-purge
Type:silverstripe-vendormodule
pkg:composer/springtimesoft/silverstripe-cloudflare-assets-purge
Requires
- ext-curl: *
- silverstripe/framework: ^5
- symbiote/silverstripe-queuedjobs: ^5
This package is auto-updated.
Last update: 2026-08-23 22:43:46 UTC
README
Automatically purges the Cloudflare cache when Silverstripe assets are published, unpublished, or deleted, and after a dev/build.
Requirements
- Silverstripe ^5
- symbiote/silverstripe-queuedjobs ^5
Installation
composer require springtimesoft/silverstripe-cloudflare-assets-purge
Configuration
Add the following environment variables to your .env:
CLOUDFLARE_PURGE_ZONE_ID="your-zone-id"
CLOUDFLARE_PURGE_API_TOKEN="your-api-token"
The API token requires the Cache Purge permission on the target zone. See below for instructions on creating a Cloudflare API token (either account level, or using personal access token).
If either variable is absent the module silently does nothing, so it is safe to install in environments where Cloudflare is not configured (e.g. local development).
Additionally, you must have the queued jobs module installed, with a cron job configured to process its queue.
How it works
- File / Image publish - queues a full-zone cache purge via
FileCachePurgeExtension::onAfterPublish. - File / Image unpublish - queues a purge via
FileCachePurgeExtension::onAfterUnpublish. - File / Image delete - queues a purge only when a live version exists (draft-only files have nothing cached).
- dev/build - queues a purge via
DevBuildCachePurgeExtension::onAfterBuild.
Purges are handled asynchronously by PurgeWebsiteAssetsJob, which calls the Cloudflare Cache Purge API with purge_everything: true. This flushes the entire zone cache - not just assets - so pages, CSS, JS, and any other cached responses will also be invalidated.
Creating a Cloudflare API Key
You will need to configure this module with an existing Cloudflare API token. This API token can either be an Account API token, or a personal access token.
Creating an account API token
- Log in to your Cloudflare account.
- Navigate to your account →
Manage account→Account API tokens. - Click
Create Token. - Provide a reference token name.
- Select
Start from scratch. - In the
Edit policysection, changeEntire accounttoSpecified Domains, and select your domain from the list. - In the
Search for permission groupssearch forCacheand select thePurgeoption. Token expiration: No expiration.Client IP address filtering: leave blank.- Click
Review token, thenCreate token - Make a note of the API token (this will be displayed only once). Note: that the account ID is not the same as the zone ID. You can find your zone ID in the Cloudflare dashboard under
Overviewfor your domain (bottom right of page). - Add the token to your
.envfile asCLOUDFLARE_PURGE_API_TOKENand the zone ID asCLOUDFLARE_PURGE_ZONE_ID.
Creating a personal access token
- Within your Cloudflare account, navigate to
My Profile→API Tokens. - Select
Create Custom Token. - Provide a reference token name.
- Under permissions, select
Zone→Cache Purge→Purge. - Under
Zone Resources, selectInclude→Specific zoneand select your domain from the list. - Leave the remaining fields blank, and click
Continue to summary. - Click "Create Token" and make a note of the API token (this will be displayed only once).
- You can find your zone ID in the Cloudflare dashboard under
Overviewfor your domain (bottom right of page). - Add the token to your
.envfile asCLOUDFLARE_PURGE_API_TOKENand the zone ID asCLOUDFLARE_PURGE_ZONE_ID.
License
MIT License. See LICENSE for details.