PHPackages                             eminos/statamic-cloudflare-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. eminos/statamic-cloudflare-cache

ActiveStatamic-addon[Caching](/categories/caching)

eminos/statamic-cloudflare-cache
================================

Cloudflare cache integration for Statamic

v1.5.0(4mo ago)24782MITPHPPHP ^8.0CI passing

Since Apr 11Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/eminos/statamic-cloudflare-cache)[ Packagist](https://packagist.org/packages/eminos/statamic-cloudflare-cache)[ RSS](/packages/eminos-statamic-cloudflare-cache/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

Statamic Cloudflare Cache
=========================

[](#statamic-cloudflare-cache)

Automatically purge your Cloudflare cache when content changes in Statamic.

Features
--------

[](#features)

- Automatically purges Cloudflare cache when Statamic content changes.
- **Multi-zone support** for Statamic multisite installations with different domains.
- Configurable events that trigger cache purging.
- Optional support for Statamic `static_caching` invalidation rules via `UrlInvalidated`/`StaticCacheCleared` events.
- Optional queuing of purge jobs for background processing.
- CLI command for manual cache purging.
- Simple configuration with backward compatibility.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require eminos/statamic-cloudflare-cache
```

Publish the config file:

```
php artisan vendor:publish --tag="cloudflare-cache-config"
```

Configuration
-------------

[](#configuration)

### Basic Setup (Single Zone)

[](#basic-setup-single-zone)

Add the following environment variables to your `.env` file:

```
CLOUDFLARE_API_TOKEN=your-api-token
CLOUDFLARE_ZONE_ID=your-zone-id
CLOUDFLARE_CACHE_ENABLED=true
CLOUDFLARE_CACHE_QUEUE_PURGE=false # Optional: Set to true to dispatch purges to the queue
CLOUDFLARE_CACHE_DEBUG=false # Optional: Set to true to log API calls

```

### Multi-Zone Setup (Multisite)

[](#multi-zone-setup-multisite)

For Statamic multisite installations with multiple domains, you can configure multiple Cloudflare zones. The package uses a single API token for all zones.

In your `config/cloudflare-cache.php` file, add your zone mappings:

```
'zones' => [
    // Map domains to zone IDs
    'example.com' => 'zone_id_123',
    'example.fr' => 'zone_id_456',
],
```

The package will automatically detect which zone to use based on the URL being purged. It will:

1. First try to match the exact domain from the URL
2. Then try without '[www](http://www).' prefix (so 'example.com' will match '[www.example.com](http://www.example.com)')
3. Fall back to the default `zone_id` if no match is found

### Getting Your Cloudflare Credentials

[](#getting-your-cloudflare-credentials)

You can get your API token and Zone IDs from the Cloudflare dashboard:

1. **API Token**: Log in to your Cloudflare dashboard, go to "My Profile" &gt; "API Tokens" and create a token with the "Zone.Cache Purge" permission for all zones you want to manage.
2. **Zone ID**: Go to your domain's overview page in Cloudflare. The Zone ID is displayed in the right sidebar under "API" section.

Usage
-----

[](#usage)

### Automatic Cache Purging

[](#automatic-cache-purging)

Once configured, the addon will automatically purge the Cloudflare cache when content changes in Statamic. By default, it listens for the following events:

- Entry saved/deleted
- Term saved/deleted
- Asset saved/deleted
- Global set saved/deleted (purges everything via `purge_everything_fallback`)

You can configure which events trigger cache purging in the config file.

#### Event handling modes (either/or)

[](#event-handling-modes-eitheror)

- **Default (`use_statamic_static_cache_invalidation = false`)**: uses this addon’s own content events (`entry_*`, `term_*`, `asset_*`, etc.).
- **Statamic static cache mode (`use_statamic_static_cache_invalidation = true`)**: uses Statamic Static Cache events (`url_invalidated`, `static_cache_cleared`) and skips the addon’s legacy content events.

#### Queued Purging

[](#queued-purging)

If you prefer to handle cache purging in the background to avoid potential delays during web requests, you can enable queued purging. Set the `CLOUDFLARE_CACHE_QUEUE_PURGE` environment variable to `true` or set `'queue_purge' => true` in the configuration file.

When enabled, purge operations triggered by events will be dispatched as jobs to your application's queue. **Note:** This requires you to have a queue worker running (`php artisan queue:work`).

### Manual Cache Purging

[](#manual-cache-purging)

You can manually purge the cache using the following command:

```
# Purge all cache (all zones if multi-zone is configured)
php please cloudflare:purge

# Purge specific URL (automatically detects the correct zone)
php please cloudflare:purge --url=https://example.com/specific-page

# Purge specific zone by ID
php please cloudflare:purge --zone=zone_id_123

# Purge specific domain (requires multi-zone configuration)
php please cloudflare:purge --domain=example.fr
```

Advanced Configuration
----------------------

[](#advanced-configuration)

The published configuration file (`config/cloudflare-cache.php`) allows you to customize the behavior of the addon:

```
return [
    // Enable or disable the addon
    'enabled' => env('CLOUDFLARE_CACHE_ENABLED', true),

    // Cloudflare API credentials
    'api_token' => env('CLOUDFLARE_API_TOKEN', ''),

    // Single zone configuration (backward compatibility)
    'zone_id' => env('CLOUDFLARE_ZONE_ID', ''),

    // Multi-zone configuration for multisite setups
    'zones' => [
        // 'domain.com' => 'zone_id_here',
        // 'another-domain.com' => 'another_zone_id',
    ],

    // Configure which events trigger cache purging
    'purge_on' => [
        'entry_saved' => true,
        'entry_deleted' => true,
        'term_saved' => true,
        'term_deleted' => true,
        'asset_saved' => true,
        'asset_deleted' => true,
        'collection_tree_saved' => true,
        'nav_tree_saved' => true,
        'global_set_saved' => true,
        'global_set_deleted' => true,
        'url_invalidated' => true, // Statamic Static Cache: UrlInvalidated event
        'static_cache_cleared' => true, // Statamic Static Cache: StaticCacheCleared event
    ],

    // When enabled, only Statamic Static Cache events are handled (UrlInvalidated/StaticCacheCleared).
    // Legacy addon content events are skipped in this mode.
    'use_statamic_static_cache_invalidation' => env('CLOUDFLARE_CACHE_USE_STATAMIC_STATIC_CACHE_INVALIDATION', false),

    // Dispatch purge jobs to the queue instead of running synchronously
    'queue_purge' => env('CLOUDFLARE_CACHE_QUEUE_PURGE', false),

    // Advanced settings
    'purge_urls' => true, // Purge specific URLs if possible
    'purge_everything_fallback' => true, // Fallback to purging everything if specific URLs can't be determined
    'debug' => env('CLOUDFLARE_CACHE_DEBUG', false), // Log API call attempts when purging
];
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance77

Regular maintenance activity

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~46 days

Total

6

Last Release

124d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f7b9b5acefc797c0c0cf24b4b05ce1f55e50a0c20e5bdbf647eae53b0a16fab?d=identicon)[eminos](/maintainers/eminos)

---

Top Contributors

[![eminos](https://avatars.githubusercontent.com/u/1682784?v=4)](https://github.com/eminos "eminos (4 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")[![mthorsdal](https://avatars.githubusercontent.com/u/36050618?v=4)](https://github.com/mthorsdal "mthorsdal (1 commits)")[![sheadawson](https://avatars.githubusercontent.com/u/1166136?v=4)](https://github.com/sheadawson "sheadawson (1 commits)")

---

Tags

cloudflarecloudflare-cachestatamicstatamic-addonstatamic-v5statamic-v6

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/eminos-statamic-cloudflare-cache/health.svg)

```
[![Health](https://phpackages.com/badges/eminos-statamic-cloudflare-cache/health.svg)](https://phpackages.com/packages/eminos-statamic-cloudflare-cache)
```

###  Alternatives

[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135212.4k7](/packages/statamic-rad-pack-runway)[statamic/seo-pro

68488.6k](/packages/statamic-seo-pro)[thoughtco/statamic-cache-tracker

1936.9k](/packages/thoughtco-statamic-cache-tracker)[rias/statamic-redirect

29322.9k](/packages/rias-statamic-redirect)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3310.1k](/packages/duncanmcclean-statamic-cargo)[statamic-rad-pack/mailchimp

Subscribe registrations or contact forms to Mailchimp

1821.0k](/packages/statamic-rad-pack-mailchimp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
