HastyEgg Cloudflare Cache Purge
hastyegg/module-cloudflare
Automatically purges the entire Cloudflare cache whenever Magento cache is flushed from the admin panel or CLI, ensuring customers always see up-to-date content behind the Cloudflare CDN.
Build Tests
Code Quality
Tested on Magento 2.4.8-p4
Recent Test History
Each release is tested against the latest Magento version at that time.
Top Contributors
View LeaderboardShare This Module's Status
README
Loaded from GitHubhastyegg-magento-cloudflare
Keep your storefront in sync — automatically.
When you manage a Magento store behind Cloudflare, cached pages can serve stale content after product updates, price changes, or CMS edits. This module eliminates that gap by automatically purging your entire Cloudflare cache every time Magento's cache is flushed — whether from the Admin Panel or the command line.
Why This Matters
- No more stale pages. Customers always see the latest prices, inventory, and content.
- Zero manual steps. Your team doesn't need to log into Cloudflare to purge after every change.
- Instant verification. Credentials are validated on save so you know the connection works before anything goes live.
- No performance impact. The module only fires during cache flush events — it adds nothing to page load or checkout.
Features
| Feature | Description |
|---|---|
| Automatic Purge | Triggers a Cloudflare "Purge Everything" on any Magento cache flush |
| Connection Verification | Tests your API credentials when you hit Save Config and shows a success or error message |
| Encrypted Storage | API tokens are stored using Magento's native encryption — never in plain text |
| Admin Configuration | Simple setup under Stores → Configuration with no code changes required |
| Logging | All purge attempts (success and failure) are logged to var/log/system.log |
Compatibility
- Magento 2.4.x (Open Source & Commerce)
- PHP 8.1+
- Cloudflare Free, Pro, Business, or Enterprise plan
Installation
composer require hastyegg/module-cloudflare
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:flush
Configuration
- Log in to the Magento Admin Panel
- Navigate to Stores → Configuration → General → Cloudflare
- Fill in the settings:
| Setting | Where to Find It |
|---|---|
| Enable | Set to Yes to activate |
| Zone ID | Cloudflare Dashboard → your domain → Overview (right sidebar) |
| API Token | Cloudflare Dashboard → My Profile → API Tokens → Create Token |
- Click Save Config
- A green success message confirms the connection: "Connected to Cloudflare zone example.com successfully."
Creating a Cloudflare API Token
- Go to Cloudflare API Tokens
- Click Create Token
- Use the Custom Token template
- Set permissions to: Zone → Cache Purge → Purge
- Under Zone Resources, select your specific domain
- Click Continue to Summary → Create Token
- Copy the token into the Magento configuration
Cache Events
The module listens to the following Magento events:
| Event | Trigger |
|---|---|
adminhtml_cache_flush_all |
Admin → System → Cache Management → Flush Magento Cache |
adminhtml_cache_flush_system |
Admin → System → Cache Management → Flush Cache Storage |
clean_cache_by_tags |
Programmatic cache clean by tags |
Module Structure
app/code/HastyEgg/Cloudflare/
├── Model/
│ └── CachePurger.php # Cloudflare API client (purge & verify)
├── Observer/
│ ├── PurgeCloudflareCache.php # Listens for cache flush events
│ └── VerifyCloudflareCredentials.php # Validates credentials on config save
├── etc/
│ ├── acl.xml # Admin permissions
│ ├── adminhtml/
│ │ ├── events.xml # Config save verification event
│ │ └── system.xml # Admin configuration fields
│ ├── config.xml # Default configuration values
│ ├── events.xml # Cache flush event observers
│ └── module.xml # Module declaration
└── registration.php # Module registration
Troubleshooting
| Problem | Solution |
|---|---|
| "Zone ID or API Token is missing" warning | Ensure both fields are filled in and saved |
| "Cloudflare API error: Invalid API Token" | Regenerate the token in Cloudflare with Zone.Cache Purge permission |
| Purge not firing | Confirm Enable is set to Yes and check var/log/system.log for details |
| 403 from Cloudflare API | The token may not have permission for the specified Zone ID |
This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.