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

ActiveLibrary[Caching](/categories/caching)

ckdot/page-cache
================

Caches responses as static files on disk for lightning fast page loads..

v1.0.1(8y ago)0292MITPHPPHP &gt;=5.5.9

Since Oct 15Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ckdot/page-cache)[ Packagist](https://packagist.org/packages/ckdot/page-cache)[ RSS](/packages/ckdot-page-cache/feed)WikiDiscussions master Synced 2d ago

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

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

[](#laravel-page-cache)

This package allows you to easily cache responses as static files on disk for lightning fast page loads.

- [Introduction](#introduction)
- [Installation](#installation)
    - [Service Provider](#service-provider)
    - [Middleware](#middleware)
    - [URL rewriting](#url-rewriting)
    - [Ignoring the cached files](#ignoring-the-cached-files)
- [Usage](#usage)
    - [Using the middleware](#using-the-middleware)
    - [Clearing the cache](#clearing-the-cache)
- [License](#license)

---

Introduction
------------

[](#introduction)

While static site builders such as [Jekyll](https://jekyllrb.com/) and [Jigsaw](http://jigsaw.tighten.co/) are extremely popular these days, dynamic PHP sites still offer a lot of value even for a site that is mostly static. A proper PHP site allows you to easily add dynamic functionality wherever needed, and also means that there's no build step involved in pushing updates to the site.

That said, for truly static pages on a site there really is no reason to have to boot up a full PHP app just to serve a static page. Serving a simple HTML page from disk is infinitely faster and less taxing on the server.

The solution? Full page caching.

Using the middleware included in this package, you can selectively cache the response to disk for any given request. Subsequent calls to the same page will be served directly as a static HTML page!

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

[](#installation)

Install the `page-cache` package with composer:

```
$ composer require silber/page-cache

```

### Service Provider

[](#service-provider)

> **Note**: If you're using Laravel 5.5+, the service provider will be registered automatically. You can simply skip this step entirely.

Open `config/app.php` and add a new item to the `providers` array:

```
Silber\PageCache\LaravelServiceProvider::class,
```

### Middleware

[](#middleware)

Open `app/Http/Kernel.php` and add a new item to the `web` middleware group:

```
protected $middlewareGroups = [
    'web' => [
        \Silber\PageCache\Middleware\CacheResponse::class,
        /* ... keep the existing middleware here */
    ],
];
```

The middleware is smart enough to only cache responses with a 200 HTTP status code, and only for GET requests.

If you want to selectively cache only specific requests to your site, you should instead add a new mapping to the `routeMiddleware` array:

```
protected $routeMiddleware = [
    'page-cache' => Silber\PageCache\Middleware\CacheResponse::class,
    /* ... keep the existing mappings here */
];
```

Once registered, you can then [use this middleware on individual routes](#using-the-middleware).

### URL rewriting

[](#url-rewriting)

In order to serve the static files directly once they've been cached, you need to properly configure your web server to check for those static files.

- **For nginx:**

    Update your `location` block's `try_files` directive to include a check in the `page-cache` directory:

    ```
    location = / {
        try_files /page-cache/pc__index__pc.html /index.php?$query_string;
    }

    location / {
        try_files $uri $uri/ /page-cache/$uri.html /index.php?$query_string;
    }
    ```
- **For apache:**

    Open `public/.htaccess` and add the following before the block labeled `Handle Front Controller`:

    ```
    # Serve Cached Page If Available...
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{DOCUMENT_ROOT}/page-cache/pc__index__pc.html -f
    RewriteRule .? page-cache/pc__index__pc.html [L]
    RewriteCond %{DOCUMENT_ROOT}/page-cache%{REQUEST_URI}.html -f
    RewriteRule . page-cache%{REQUEST_URI}.html [L]
    ```

### Ignoring the cached files

[](#ignoring-the-cached-files)

To make sure you don't commit your locally cached files to your git repository, add this line to your `.gitignore` file:

```
/public/page-cache

```

Usage
-----

[](#usage)

### Using the middleware

[](#using-the-middleware)

> **Note:** If you've added the middleware to the global `web` group, then all successful GET requests will automatically be cached. No need to put the middleware again directly on the route.
>
> If you instead registered it as a route middleware, you should use the middleware on whichever routes you want to be cached.

To cache the response of a given request, use the `page-cache` middleware:

```
Route::middleware('page-cache')->get('posts/{slug}', 'PostController@show');
```

Every post will now be cached to a file under the `public/page-cache` directory, closely matching the URL structure of the request. All subsequent requests for this post will be served directly from disk, never even hitting your app!

### Clearing the cache

[](#clearing-the-cache)

Since the responses are cached to disk as static files, any updates to those pages in your app will not be reflected on your site. To update pages on your site, you should clear the cache with the following command:

```
php artisan page-cache:clear

```

As a rule of thumb, it's good practice to add this to your deployment script. That way, whenever you push an update to your site the page cache will automatically be cleared.

If you're using [Forge](https://forge.laravel.com)'s Quick Deploy feature, you should add this line to the end of your Deploy Script. This'll ensure that the cache is cleared whenever you push an update to your site.

License
-------

[](#license)

The Page Cache package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~148 days

Total

2

Last Release

2985d ago

### Community

Maintainers

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

---

Top Contributors

[![JosephSilber](https://avatars.githubusercontent.com/u/1403741?v=4)](https://github.com/JosephSilber "JosephSilber (20 commits)")[![ckilb](https://avatars.githubusercontent.com/u/7283097?v=4)](https://github.com/ckilb "ckilb (4 commits)")

---

Tags

laravelcache

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[silber/page-cache

Caches responses as static files on disk for lightning fast page loads.

1.3k441.9k6](/packages/silber-page-cache)[dragon-code/laravel-cache

An improved interface for working with cache

6844.8k10](/packages/dragon-code-laravel-cache)[antennaio/laravel-clyde

Image uploads and manipulation for Laravel, a wrapper around Glide

292.6k](/packages/antennaio-laravel-clyde)

PHPackages © 2026

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