Download the PHP package springtimesoft/silverstripe-cloudflare-assets-purge without Composer
On this page you can find all versions of the php package springtimesoft/silverstripe-cloudflare-assets-purge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download springtimesoft/silverstripe-cloudflare-assets-purge
More information about springtimesoft/silverstripe-cloudflare-assets-purge
Files in springtimesoft/silverstripe-cloudflare-assets-purge
Package silverstripe-cloudflare-assets-purge
Short Description Queues a Cloudflare cache purge when Silverstripe assets are published, unpublished, or deleted
License MIT
Homepage https://github.com/springtimesoft/silverstripe-cloudflare-assets-purge
Informations about the package silverstripe-cloudflare-assets-purge
Silverstripe Cloudflare Assets Purge
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
Configuration
Add the following environment variables to your .env:
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.
All versions of silverstripe-cloudflare-assets-purge with dependencies
silverstripe/framework Version ^6
symbiote/silverstripe-queuedjobs Version ^6