hastyegg/module-cloudflare 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hastyegg/module-cloudflare

最新稳定版本:v1.0.0

Composer 安装命令:

composer require hastyegg/module-cloudflare

包简介

Magento 2 module — automatically purge Cloudflare cache on Magento cache flush

README 文档

README

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

  1. Log in to the Magento Admin Panel
  2. Navigate to Stores → Configuration → General → Cloudflare
  3. 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
  1. Click Save Config
  2. A green success message confirms the connection: "Connected to Cloudflare zone example.com successfully."

Creating a Cloudflare API Token

  1. Go to Cloudflare API Tokens
  2. Click Create Token
  3. Use the Custom Token template
  4. Set permissions to: Zone → Cache Purge → Purge
  5. Under Zone Resources, select your specific domain
  6. Click Continue to Summary → Create Token
  7. 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

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固