PHPackages                             illuma-law/laravel-edge-clear - 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. illuma-law/laravel-edge-clear

ActiveLibrary[Caching](/categories/caching)

illuma-law/laravel-edge-clear
=============================

Standalone Cloudflare cache purging for Laravel

v0.1.4(1mo ago)062MITPHPPHP ^8.3CI passing

Since Apr 20Pushed 1mo agoCompare

[ Source](https://github.com/illuma-law/laravel-edge-clear)[ Packagist](https://packagist.org/packages/illuma-law/laravel-edge-clear)[ RSS](/packages/illuma-law-laravel-edge-clear/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (15)Versions (6)Used By (0)

Laravel Edge Clear
==================

[](#laravel-edge-clear)

[![Tests](https://github.com/illuma-law/laravel-edge-clear/actions/workflows/run-tests.yml/badge.svg)](https://github.com/illuma-law/laravel-edge-clear/actions)[![Packagist License](https://camo.githubusercontent.com/e60623f508586f049d48cfb8396ee411b0c9bc3be174381a1893c37462a3c1e5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e63652d4d49542d626c7565)](http://choosealicense.com/licenses/mit/)[![Latest Stable Version](https://camo.githubusercontent.com/bc6f4fb54568734c2cad2d5ce96ba45d72261737a3a1ec6c10b9445bdfac6617/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696c6c756d612d6c61772f6c61726176656c2d656467652d636c6561723f6c6162656c3d56657273696f6e)](https://packagist.org/packages/illuma-law/laravel-edge-clear)

Standalone Cloudflare cache purging and cache bypass management for Laravel applications.

This package provides a fluent service, a Facade, and specialized middleware designed to help you manage your Cloudflare CDN cache directly from your Laravel application.

Features
--------

[](#features)

- **Purge Specific URLs:** Invalidate only the pages that have changed.
- **Purge by Tags:** Quickly wipe out categories of content across your site using Cloudflare Cache Tags (requires Cloudflare Enterprise).
- **Purge Everything:** The "nuke from orbit" option.
- **Generic Purge Job:** A robust `PurgeEdgeCacheJob` that handles automatic fallback from tag-based purging to URL-based purging if Enterprise features are missing.
- **Set Cache Headers Middleware:** Easily manage `Cache-Control` and `Cache-Tag` headers for your routes.
- **Cache Bypass Middleware:** Attach middleware to specific routes or controllers to ensure Cloudflare never caches them.
- **Lifecycle Events:** Listen to `EdgeCachePurged` and `EdgeCachePurgeFailed` to keep your application state in sync with the CDN.
- **Environment Awareness:** Safely test your code locally without accidentally triggering real API calls.

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

[](#installation)

You can install the package via composer:

```
composer require illuma-law/laravel-edge-clear
```

You can publish the config file with:

```
php artisan vendor:publish --tag="edge-clear-config"
```

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

[](#configuration)

In your `.env` file, configure your Cloudflare credentials. You can use either an API Token (recommended) or an API Email + Key combo.

```
CLOUDFLARE_ZONE_ID="your-zone-id"
CLOUDFLARE_API_TOKEN="your-api-token"
```

The published `config/edge-clear.php` config looks like this:

```
return [
    'zone_id' => env('CLOUDFLARE_ZONE_ID'),

    // Auth method 1 (Preferred)
    'api_token' => env('CLOUDFLARE_API_TOKEN'),

    // Auth method 2
    'api_email' => env('CLOUDFLARE_API_EMAIL'),
    'api_key' => env('CLOUDFLARE_API_KEY'),

    // Toggle the service globally
    'enabled' => env('CLOUDFLARE_ENABLED', true),

    // Prevent accidental API calls in local dev
    'only_in_production' => env('CLOUDFLARE_ONLY_IN_PRODUCTION', true),

    // Enable detailed API request logging
    'debug' => env('CLOUDFLARE_DEBUG', false),
];
```

Usage &amp; Integration
-----------------------

[](#usage--integration)

### Triggering Purges

[](#triggering-purges)

Use the `CloudflarePurger` facade to interact with the cache:

```
use IllumaLaw\EdgeClear\Facades\CloudflarePurger;

// Purge specific URLs (Useful in Model Observers)
CloudflarePurger::purgeByUrls([
    'https://example.com/blog/my-updated-post',
    'https://example.com/blog',
]);

// Purge by cache tags (Requires Cloudflare Enterprise)
CloudflarePurger::purgeByTags(['tag:blog', 'tag:news']);

// Purge the entire zone cache (Useful after deploying huge site changes)
CloudflarePurger::purgeEverything();
```

### Real-world Example: Eloquent Observer

[](#real-world-example-eloquent-observer)

Invalidate your cache automatically when a model is saved or deleted:

```
namespace App\Observers;

use App\Models\Post;
use IllumaLaw\EdgeClear\Facades\CloudflarePurger;

class PostObserver
{
    public function saved(Post $post): void
    {
        // Purge the specific post and the blog index
        CloudflarePurger::purgeByUrls([
            url("/blog/{$post->slug}"),
            url('/blog'),
        ]);
    }
}
```

### Route Middleware

[](#route-middleware)

If you have specific routes that should never be cached by Cloudflare (like admin dashboards, carts, or user profiles), you can use the `BypassEdgeCache` middleware. It automatically appends headers (`Cache-Control: no-store, no-cache...`) that instruct Cloudflare to skip caching the response.

```
use IllumaLaw\EdgeClear\Middleware\BypassEdgeCache;

Route::get('/admin/dashboard', [DashboardController::class, 'index'])
    ->middleware(BypassEdgeCache::class);
```

### Set Cache Headers

[](#set-cache-headers)

Use the `SetEdgeCacheHeaders` middleware to manage your CDN headers fluently. It handles `Cache-Control` (including `s-maxage`) and `Cache-Tag` injection.

```
use IllumaLaw\EdgeClear\Middleware\SetEdgeCacheHeaders;

Route::get('/public-news', [NewsController::class, 'index'])
    ->middleware(SetEdgeCacheHeaders::class.':600;tag:news;short');
```

The middleware parameters are: `ttl`, `tags` (separated by `;`), and `profile` (`short` or `permanent`).

### Queued Purging (with Fallback)

[](#queued-purging-with-fallback)

For high-volume sites, you can use the `PurgeEdgeCacheJob`. It automatically detects if your Cloudflare plan supports Cache Tags and falls back to URL purging if needed.

```
use IllumaLaw\EdgeClear\Jobs\PurgeEdgeCacheJob;

PurgeEdgeCacheJob::dispatch(
    tags: ['tag:blog'],
    urls: ['https://example.com/blog'],
    reason: 'blog_updated'
);
```

### Lifecycle Events

[](#lifecycle-events)

The package dispatches events that you can listen to for logging or updating your application state:

- `IllumaLaw\EdgeClear\Events\EdgeCachePurged`: Dispatched when a purge request is successful.
- `IllumaLaw\EdgeClear\Events\EdgeCachePurgeFailed`: Dispatched when a purge request fails after all retries.

### Error Handling

[](#error-handling)

If Cloudflare rejects your request (e.g., bad token, invalid URLs), the package will throw a typed `CloudflarePurgeException`.

```
use IllumaLaw\EdgeClear\Exceptions\CloudflarePurgeException;
use IllumaLaw\EdgeClear\Facades\CloudflarePurger;

try {
    CloudflarePurger::purgeEverything();
} catch (CloudflarePurgeException $e) {
    Log::error('Cache purge failed', [
        'message' => $e->getMessage(),
        'http_status' => $e->getHttpStatus(),
        'cf_error_code' => $e->getCloudflareErrorCode(),
    ]);
}
```

Testing
-------

[](#testing)

The package includes a comprehensive test suite using Pest.

```
composer test
```

License
-------

[](#license)

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

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance91

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

5

Last Release

44d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2affac64f2726a640084b203503518ca01f582536d60a0a299b614486ed95aaa?d=identicon)[miguelenes](/maintainers/miguelenes)

---

Top Contributors

[![miguelenes](https://avatars.githubusercontent.com/u/1568086?v=4)](https://github.com/miguelenes "miguelenes (10 commits)")

---

Tags

laravelcachecloudflarecdnpurgeedgeilluma-law

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/illuma-law-laravel-edge-clear/health.svg)

```
[![Health](https://phpackages.com/badges/illuma-law-laravel-edge-clear/health.svg)](https://phpackages.com/packages/illuma-law-laravel-edge-clear)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76318.2M110](/packages/laravel-mcp)[spatie/laravel-health

Monitor the health of a Laravel application

88011.3M149](/packages/spatie-laravel-health)[ralphjsmit/laravel-glide

Auto-magically generate responsive images from static image files.

4923.6k5](/packages/ralphjsmit-laravel-glide)

PHPackages © 2026

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