aceextension / module-cloudflare-cache
Cloudflare cache purge integration for Magento 2
Package info
github.com/aceextension/module-cloudflare-cache
Type:magento2-module
pkg:composer/aceextension/module-cloudflare-cache
Requires
- aceextension/ace-core: ^1.0
This package is auto-updated.
Last update: 2026-04-20 12:00:41 UTC
README
Cloudflare cache purge integration for Magento 2. Automatically triggers a Cloudflare purge when Magento cache is cleaned or flushed (via Admin or CLI).
Features
- Purges Cloudflare cache whenever Magento cache is:
- Cleaned (cache:clean / Admin “Flush Magento Cache”)
- Flushed (cache:flush / Admin “Flush Cache Storage”)
- Admin configuration for:
- Enable/Disable integration
- Cloudflare Zone ID
- API Token (stored encrypted)
- Purge Everything toggle
- Depends on
Aceextension_Corefor shared helpers.
Requirements
- Magento 2.4.x
- PHP 8.1 or newer
- A Cloudflare API Token with permission to “Cache Purge” for the target Zone
Installation
-
Place the module in
app/code/Aceextension/CloudflareCache. -
Run the usual setup commands:
php bin/magento setup:upgrade php bin/magento cache:flush
-
(Optional) If you use Composer for local modules, ensure autoload is refreshed:
composer dump-autoload
Configuration
- Navigate to: Stores → Configuration → Ace Extensions → Cloudflare Cache
- Settings:
- Enable Integration: Yes/No
- Zone ID: Your Cloudflare Zone ID (found in Cloudflare dashboard)
- API Token: A token with purge permission for the Zone (stored encrypted)
- Purge Everything: Yes/No
Save configuration and clear Magento cache after changes.
How It Works
- The module attaches a plugin to Magento’s Cache Manager:
afterCleanandafterFlushautomatically call the Cloudflare API.
- API endpoint used:
POST https://api.cloudflare.com/client/v4/zones/{ZONE_ID}/purge_cache- Authorization:
Bearer {API_TOKEN}
- Payload:
- When “Purge Everything” is enabled,
{"purge_everything": true}is sent. - (Future extension can add URL/Host/Tag-specific payloads.)
- When “Purge Everything” is enabled,
Testing
-
Configure Zone ID and API Token in Admin.
-
Run:
php bin/magento cache:clean
-
Verify in Cloudflare dashboard that a purge occurred, or check Magento logs for entries related to Cloudflare purge status.
Security Notes
- The API Token is stored using Magento’s encrypted backend model and is never logged.
- If a purge fails, only status/error messages are logged without secrets.
- Use a least-privilege API token scoped to the required Zone and “Cache Purge” permission.
Troubleshooting
- No purge happens:
- Ensure “Enable Integration” is set to Yes.
- Verify Zone ID and API Token.
- Check that cache clean/flush actually runs (Admin or CLI).
- API errors in logs:
- Confirm the token has the correct permissions and the Zone ID is correct.
- Check outbound connectivity to
api.cloudflare.comfrom your environment.
Extending
- Purge by URLs/Hosts/Cache-Tags:
- Add new config fields for modes and a UI for entering URLs/hosts.
- Update
Model/Client.phpto build appropriate payloads (files,hosts, ortags).
- Selective triggers:
- Narrow the plugin logic to specific cache types by inspecting
$typesinafterClean.
- Narrow the plugin logic to specific cache types by inspecting
- CLI command:
- Add a Magento CLI command to manually purge Cloudflare on demand.
Module Structure
etc/module.xml– module declaration, depends onAceextension_Coreetc/adminhtml/system.xml– Admin configuration fieldsetc/acl.xml– Admin ACL for configurationetc/di.xml– Plugin registration for Cache ManagerHelper/Data.php– Configuration access (extends Core helper)Model/Client.php– Cloudflare API client (Curl-based)Plugin/CacheManagerPlugin.php– Hooks into cache clean/flush
Uninstall
-
Disable the module and remove its directory:
php bin/magento module:disable Aceextension_CloudflareCache rm -rf app/code/Aceextension/CloudflareCache php bin/magento setup:upgrade php bin/magento cache:flush