PHPackages                             jeffersongoncalves/laravel-page-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. jeffersongoncalves/laravel-page-cache

ActiveLibrary[Caching](/categories/caching)

jeffersongoncalves/laravel-page-cache
=====================================

This Laravel package provides a full-page response cache middleware for stateless public GET pages. It caches 200 responses keyed by a version token, locale, and theme cookie, skips authenticated requests, exposes an X-Page-Cache HIT/MISS header, and offers a static flush() helper to invalidate every cached page at once.

10PHPCI passing

Since Jun 20Pushed today1 watchersCompare

[ Source](https://github.com/jeffersongoncalves/laravel-page-cache)[ Packagist](https://packagist.org/packages/jeffersongoncalves/laravel-page-cache)[ RSS](/packages/jeffersongoncalves-laravel-page-cache/feed)WikiDiscussions master Synced today

READMEChangelog (2)DependenciesVersions (2)Used By (0)

[![Laravel Page Cache](https://raw.githubusercontent.com/jeffersongoncalves/laravel-page-cache/master/art/jeffersongoncalves-laravel-page-cache.png)](https://raw.githubusercontent.com/jeffersongoncalves/laravel-page-cache/master/art/jeffersongoncalves-laravel-page-cache.png)

Laravel Page Cache
==================

[](#laravel-page-cache)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ae65c1e7b8900292133021bc352dc0963c49a36863cf2348b94fdcc90df13c91/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d706167652d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeffersongoncalves/laravel-page-cache)[![GitHub Tests Action Status](https://camo.githubusercontent.com/596b76e422a9df9a243e9c7a641a6975ef2434f80e0177b8927a7ef0090ca6aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d706167652d63616368652f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jeffersongoncalves/laravel-page-cache/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/406a05092bc12736bd0e78c22ed4d1cd26706d8d0f3c99c8a67b0a8cd140d141/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d706167652d63616368652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jeffersongoncalves/laravel-page-cache/actions?query=workflow%3A%22Fix+PHP+code+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/270057723e8ea2ecee9262a4426d764ceeda95a0a473c453df29737fc75345b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d706167652d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeffersongoncalves/laravel-page-cache)

This Laravel package provides a full-page response cache middleware for stateless public GET pages. It caches 200 responses keyed by a version token, locale, and theme cookie, skips authenticated requests, exposes an `X-Page-Cache` HIT/MISS header, and offers a static `flush()` helper to invalidate every cached page at once.

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

[](#installation)

You can install the package via composer:

```
composer require jeffersongoncalves/laravel-page-cache
```

You can publish the config file with:

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

This is the contents of the published config file:

```
return [
    'enabled' => env('PAGE_CACHE_ENABLED', true),

    'ttl' => (int) env('PAGE_CACHE_TTL', 3600),

    'key' => [
        'locale' => true,

        'theme' => [
            'enabled' => true,
            'cookie' => 'theme',
        ],
    ],
];
```

Usage
-----

[](#usage)

Register `CachePublicPage` as the outermost middleware on your public route group so cached responses are served before any other middleware runs:

```
use Illuminate\Support\Facades\Route;
use JeffersonGoncalves\PageCache\Middleware\CachePublicPage;

Route::middleware(CachePublicPage::class)->group(function () {
    Route::get('/', HomeController::class);
    Route::get('/{slug}', ShowController::class);
});
```

The first request to a path is computed normally and stored with an `X-Page-Cache: MISS` header. Subsequent requests are served straight from the cache with an `X-Page-Cache: HIT` header. Only stateless `GET` requests that return a `200` response from a guest (unauthenticated) visitor are cached.

### Invalidating the cache

[](#invalidating-the-cache)

Call `CachePublicPage::flush()` from your model observers to invalidate every cached page whenever the underlying content changes:

```
use JeffersonGoncalves\PageCache\Middleware\CachePublicPage;

class ProjectObserver
{
    public function saved(Project $project): void
    {
        CachePublicPage::flush();
    }

    public function deleted(Project $project): void
    {
        CachePublicPage::flush();
    }
}
```

`flush()` bumps an internal version token, so every previously cached page is bypassed on the next request without touching individual cache keys.

### Cache key

[](#cache-key)

By default the cache key is composed of the version token, the current locale, the theme cookie value, and a hash of the request path. You can disable the locale or theme segments — or change the theme cookie name — through the config file. The path (not the full URL) is used so the query string cannot flood the cache with variants.

Testing
-------

[](#testing)

```
composer test
```

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)

- [Jèfferson Gonçalves](https://github.com/jeffersongoncalves)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance65

Regular maintenance activity

Popularity2

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 83.3% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/411493?v=4)[Jefferson Gonçalves](/maintainers/jeffersongoncalves)[@jeffersongoncalves](https://github.com/jeffersongoncalves)

---

Top Contributors

[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (5 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

cachecomposerjeffersongoncalveslaravellaravel-packagemiddlewarepage-cacheperformancephp

### Embed Badge

![Health badge](/badges/jeffersongoncalves-laravel-page-cache/health.svg)

```
[![Health](https://phpackages.com/badges/jeffersongoncalves-laravel-page-cache/health.svg)](https://phpackages.com/packages/jeffersongoncalves-laravel-page-cache)
```

###  Alternatives

[barryvdh/laravel-httpcache

HttpCache for Laravel

513404.4k10](/packages/barryvdh-laravel-httpcache)[iron-io/iron_cache

Client binding for IronCache (A key/value store in the cloud)

1514.8k1](/packages/iron-io-iron-cache)

PHPackages © 2026

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