PHPackages                             area17/edge-flush - 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. area17/edge-flush

ActiveLibrary[Caching](/categories/caching)

area17/edge-flush
=================

CDN Cache Control and Invalidation

v2.0.7(3y ago)92.8k3MITPHPPHP ^8.0

Since Jul 28Pushed 1y ago4 watchersCompare

[ Source](https://github.com/area17/edge-flush)[ Packagist](https://packagist.org/packages/area17/edge-flush)[ Docs](https://github.com/area17/edge-flush)[ GitHub Sponsors](https://github.com/area17)[ RSS](/packages/area17-edge-flush/feed)WikiDiscussions 1.x Synced 1w ago

READMEChangelogDependencies (9)Versions (70)Used By (0)

EdgeFlush
=========

[](#edgeflush)

[![GitHub PHPUnit Action Status](https://camo.githubusercontent.com/c9ec4f8769c841c24319cb26f8a3a271d537f9a0dc3e8a823c0fc90e169eddcb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6172656131372f656467652d666c7573682f706870756e69743f6c6162656c3d504850556e6974)](https://github.com/area17/edge-flush/actions?query=workflow%3Aphpunit+branch%3A1.x)[![GitHub PHPStan Action Status](https://camo.githubusercontent.com/a9b422cc4504aa1cb23b7625107f97d330b9086b8bff77eb630205ef21a38ce2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6172656131372f656467652d666c7573682f7068707374616e3f6c6162656c3d5048505374616e)](https://github.com/area17/edge-flush/actions?query=workflow%phpstan+branch%3A1.x)

EdgeFlush is Laravel package intended to help developers manage CDN granular caching and invalidations. Having Akamai, CloudFront (or any other CDN) in front of a website, data modification usually forces us to bust the whole cache, leading to a website slow (for the first users) until the whole cache is rebuilt, and if the "first user" is Google Bot, for example, this can also impact on your website's rank. This pacakge aims to do invalidations granularly.

Feature list
------------

[](#feature-list)

- Granular invalidation: this package will create a collection of all models that impacts one page and when one of those models change, all pages that had that model rendered in previous requests will be purged from CDN.
- Granular control of Cache-Control headers: you will be able to configure it differently per request, telling the CDN to store some pages for one week and others for 5 seconds, for example.
- Single [Akamai Edge Cache Tag](#akamai-edge-cache-tags) relating to all models touched by a page render.
- Define different strategies for Cache-Control: web pages may have a different cache strategy than api endpoints.
- Prevents from caching pages containing forms.
- Caches only frontend pages, leaving the CMS uncashed, if needed.
- [Re-warm](#rewarming-cache) pages purged from cache.
- Strip cookies from cachable responses.
- Disable caching for some pages using a middlware.
- Define HTTP methods that allow caching or not: cache GET but not POST.
- Define HTTP response status codes that allow caching or not: Cache 200 and 301 but not 400+ status codes.
- Define what routes can and cannot be cached by CDN.
- Define what type of responses can be cached: cache Response but not JsonResponse, for example.
- Define what Model classes can be cached or not.
- Remember what pages have been cached and command your CDN service to burst only those when you save something on your backend.
- Supports CloudFront invalidations.
- Supports Akamai EdgeCacheTags invalidations.
- Allow override of Services and easy implementation to support new CDN Services.
- [Spatie's Laravel Response Cache](#laravel-response-cache-integration) granular invalidations.

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

[](#installation)

Install the package via composer:

```
composer require area17/edge-flush
```

Publish the config file with:

```
php artisan vendor:publish --provider="A17\EdgeFlush\ServiceProvider"
```

And run the migrations:

```
php artisan migrate
```

Dependencies
------------

[](#dependencies)

The supported CDN services have these package dependencies that you need to choose according to your setup:

Akamai: [akamai-open/edgegrid-auth](https://github.com/akamai/AkamaiOPEN-edgegrid-php)CloudFront: [aws/aws-sdk-php](https://github.com/aws/aws-sdk-php)

Usage
-----

[](#usage)

Do a full read on the `config/edge-flush.php` there's a lot of configuration items and we tried to document them all.

Define your CDN service class on `config/edge-flush.php`:

```
'classes' => [
    'cdn' => A17\EdgeFlush\Services\CloudFront\Service::class,

    ...
]
```

Add the trait `A17\EdgeFlush\Behaviours\CachedOnCDN` to your models and repositories.

Call `$this->invalidateCDNCache($model)` every time a model (on your base model or repository save() method). This example takes in consideration [Twill's](https://twill.io/) repositories:

```
public function afterSave($object, $fields)
{
    $this->invalidateCDNCache($object);

    parent::afterSave($object, $fields);
}
```

Call `$this->cacheModelOnCDN($model)` method on model's `getAttribute()`:

```
public function getAttribute($key)
{
    $this->cacheModelOnCDN($this);

    return parent::getAttribute($key);
}
```

Add the Middlware to the `Kernel.php` file:

```
protected $middleware = [
    \A17\EdgeFlush\Middleware::class,
    ...
];

```

Cache-Control max-age and s-maxage is set automatically, but if you need to change it depending on the current request you can use the following method:

```
CacheControl::setMaxAge(5000); // in seconds

CacheControl::setMaxAge('1 month'); // as a DateTime string period

CacheControl::setSMaxAge('2 weeks');
```

If you want to invalidate your paths in batches, add a scheduler setting the desired frequency for this to happen:

```
protected function schedule(Schedule $schedule)
{
    $schedule->job(new PurgeTags())->everyMinute();
}
```

You need to enable the package and the warmer on your `.env` file

```
EDGE_FLUSH_ENABLED=true
EDGE_FLUSH_WARMER_ENABLED=true
```

CDN third-party service configuration
-------------------------------------

[](#cdn-third-party-service-configuration)

Please check the respective environment variables needed for supported services to work:

- [Akamai](https://github.com/area17/edge-flush/blob/unstable/config/edge-flush.php#L188)
- [CloudFront](https://github.com/area17/edge-flush/blob/unstable/config/edge-flush.php#L195)

Rewarming cache
---------------

[](#rewarming-cache)

Purged cache pages can load slowly for the next users or even Google Bot, if you want to prevent this you can enable (on config) the cache warmer and add the job to the schedule:

```
protected function schedule(Schedule $schedule)
{
    $schedule->job(new WarmCache())->everyMinute();
}
```

Note that the most hit (or frequently updated) pages will be warmed first.

Akamai Edge Cache Tags
----------------------

[](#akamai-edge-cache-tags)

Akamai has a 128 bytes limit for the tag list, so if one page is impacted by lots of models, we would have no other way than busting the whole cache every time. This package creates a single Edge Cache Tag that relates to all models touched when the page was rendered, and adds it yo the response header:

```
edge-cache-tag: app-production-7e0ae085d699003a64e5fa7b75daae3d78ace842

```

Invalidating the full cache from the command line
-------------------------------------------------

[](#invalidating-the-full-cache-from-the-command-line)

In case you need to invalidate the whole CDN cache locally or on a deployment routing, you can:

```
php artisan edge-flush:invalidate-all

```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [AREA 17](https://github.com/area17)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~9 days

Recently: every ~0 days

Total

66

Last Release

1125d ago

Major Versions

1.x-dev → v2.0.02023-04-17

PHP version history (2 changes)v1.0.0PHP ^7.4|^8.0

v1.1.1PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9421a69d192db597169ec3519ad3efc6a35a660e4525e2ed08f6c753b908e86?d=identicon)[AntonioCarlosRibeiro](/maintainers/AntonioCarlosRibeiro)

![](https://avatars.githubusercontent.com/u/13578874?v=4)[twill](/maintainers/twill)[@twill](https://github.com/twill)

---

Top Contributors

[![antonioribeiro](https://avatars.githubusercontent.com/u/3182864?v=4)](https://github.com/antonioribeiro "antonioribeiro (145 commits)")

---

Tags

cachecdnhacktoberfestlaravelphplaravelcdnakamaicloudfrontarea17edge cache

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/area17-edge-flush/health.svg)

```
[![Health](https://phpackages.com/badges/area17-edge-flush/health.svg)](https://phpackages.com/packages/area17-edge-flush)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202541.1k6](/packages/swayok-alternative-laravel-cache)[nexxai/laravel-cfcache

A handful of Cloudflare cache helpers for Laravel

1317.7k](/packages/nexxai-laravel-cfcache)[encore/redis-manager

Redis manager for laravel

25243.1k](/packages/encore-redis-manager)[spekkionu/assetcachebuster

Prefixes asset urls with a unique hash which will allow invalidation of asset files cached by the browser.

3243.2k](/packages/spekkionu-assetcachebuster)[meema/laravel-cloudfront

Easily &amp; quickly integrate your application with AWS CloudFront.

31113.4k](/packages/meema-laravel-cloudfront)

PHPackages © 2026

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