justbetter/statamic-cloudflare-purge 问题修复 & 功能扩展

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

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

justbetter/statamic-cloudflare-purge

Composer 安装命令:

composer require justbetter/statamic-cloudflare-purge

包简介

Addon that hooks into the statamic invalidation process and purges cloudflare caches

README 文档

README

Banner

Statamic Cloudflare Purge

This addon will hook into your already existing statamic invalidation and purge any pages that have been invalidated from your Cloudflare cache.

Requirements

  • PHP ^8.3
  • Laravel ^12.0
  • Statamic ^6.7

Installation

composer require justbetter/statamic-cloudflare-purge

Usage

You need a Cloudflare API key with the Zone.Cache Purge permission, and set it in your .env:

CLOUDFLARE_API_TOKEN="token_here"

You will also have to define the zone of your website:

CLOUDFLARE_ZONE="zone_id_here"

Finally, enable the package:

CLOUDFLARE_PURGING_ENABLED=true

If you have a multistore setup with multiple zones, see the Configuration section.

This package listens to the UrlInvalidated event and adds every invalidated URL to a temp file. It also listens to certain events as defined in the config file to flush the whole cache.

Then, when you run the statamic:cloudflare:purge command or the PurgeCloudflareCachesJob job, these files will get purged from the Cloudflare cache. As such, you should add this to your routes/console.php like so:

Schedule::job(\JustBetter\StatamicCloudflarePurge\Jobs\PurgeCloudflareCachesJob::class)->everyFiveSeconds()->withoutOverlapping();

Note

Be aware of the rate limits on the API. You're probably not going to run into any issues, but it's possible. Especially if you end up calling an everything-purge often and you're on a free plan, or have a lot of sites running on the same Cloudflare account.

Configuration

You can publish the config with the following command:

php artisan vendor:publish --provider="JustBetter\StatamicCloudflarePurge\StatamicCloudflarePurgeServiceProvider"

Multiple zones

Using the configuration file you can define multiple zones. There are 3 ways of defining the zone in your config:

// Single zone
'zone' => 'zone_id',
// Multiple zones based on statamic site handles
'zone' => [
    'default' => 'zone_id_default',
    'french' => 'zone_id_french',
    ...
],
// Complete freedom with a callback
'zone' => function() {
    return \App\Facades\Custom::getCloudflareZone()
},

Cache flushing

You can define any events that will trigger a full cache purge immediately in the config file. By default, these three events have been defined for this purpose:

'flush-events' => [
    \Statamic\Events\GlobalSetSaved::class,
    \Statamic\Events\NavSaved::class,
    \Statamic\Events\StaticCacheCleared::class,
],

统计信息

  • 总下载量: 2.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固