PHPackages                             infusionweb/laravel-middleware-response-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. infusionweb/laravel-middleware-response-cache

ActiveLibrary[Caching](/categories/caching)

infusionweb/laravel-middleware-response-cache
=============================================

Provides caching of HTML pages in Laravel responses.

0.1.0(10y ago)52.4k3[1 issues](https://github.com/infusionweb/laravel-middleware-response-cache/issues)[1 PRs](https://github.com/infusionweb/laravel-middleware-response-cache/pulls)MITPHPPHP &gt;=5.5.9

Since Apr 6Pushed 9y agoCompare

[ Source](https://github.com/infusionweb/laravel-middleware-response-cache)[ Packagist](https://packagist.org/packages/infusionweb/laravel-middleware-response-cache)[ Docs](https://github.com/infusionweb/laravel-middleware-response-cache)[ RSS](/packages/infusionweb-laravel-middleware-response-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel HTML Response Cache Middleware
======================================

[](#laravel-html-response-cache-middleware)

Provides caching of entire HTML responses in Laravel 5.

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

[](#installation)

Via Composer

```
$ composer require infusionweb/laravel-middleware-response-cache
```

Laravel 5.1 Usage
-----------------

[](#laravel-51-usage)

### Add the service provider

[](#add-the-service-provider)

```
// within config/app.php

'providers' => [
    //
    InfusionWeb\Laravel\Http\Middleware\ResponseCacheServiceProvider::class,
];
```

### Register as route middleware

[](#register-as-route-middleware)

```
// within app/Http/Kernel.php

protected $routeMiddleware = [
    //
    'cachebefore' => \InfusionWeb\Laravel\Http\Middleware\ResponseCacheBeforeMiddleware::class,
    'cacheafter' => \InfusionWeb\Laravel\Http\Middleware\ResponseCacheAfterMiddleware::class,
    //
];
```

### Apply HTML response cache to routes

[](#apply-html-response-cache-to-routes)

The following will cache the `gallery` route.

```
// within app/Http/routes.php

Route::get('gallery', ['middleware' => ['cachebefore', 'cacheafter'], function () {
    return 'pictures!';
}]);
```

### Apply HTML response cache to controllers

[](#apply-html-response-cache-to-controllers)

The following will apply all default profiles to all methods within the `GalleryController`.

```
// within app/Http/Controllers/GalleryController.php

public function __construct()
{
    $this->middleware(['cachebefore', 'cacheafter']);
}
```

Laravel 5.2 Usage
-----------------

[](#laravel-52-usage)

Middleware can be registered the same as 5.1, or by the following method.

### Add to route middleware group

[](#add-to-route-middleware-group)

```
// within app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        //
        'cachebefore' => \InfusionWeb\Laravel\Http\Middleware\ResponseCacheBeforeMiddleware::class,
        'cacheafter' => \InfusionWeb\Laravel\Http\Middleware\ResponseCacheAfterMiddleware::class,
        //
    ],
    //
];
```

### Apply HTML response cache to routes

[](#apply-html-response-cache-to-routes-1)

All routes using the `web` middleware group will be cached.

```
// within app/Http/routes.php

Route::group(['middleware' => ['web']], function () {
    Route::get('gallery', function () {
        return 'pictures!';
    });
});
```

Enable and configure response caching
-------------------------------------

[](#enable-and-configure-response-caching)

The middleware will only cache HTML responses when explicitly enabled. This is to allow development systems to operate normally by default, while easily allowing production systems to cache HTML responses.

### Publish the package config file

[](#publish-the-package-config-file)

```
$ php artisan vendor:publish --provider="InfusionWeb\Laravel\Http\Middleware\ResponseCacheServiceProvider"
```

You may now enable response caching and change the default cache time by editing the `config/response-cache.php` file.

```
return [
    'enable' => env('RESPONSE_CACHE_ENABLE', false),

    // Length of time to cache the HTML response, in minutes.
    'length' => env('RESPONSE_CACHE_LENGTH', 60),
];
```

Credits
-------

[](#credits)

- [Russell Keppner](https://github.com/rkeppner)
- [All Contributors](https://github.com/InfusionWeb/laravel-middleware-response-cache/contributors)

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

3686d ago

### Community

Maintainers

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

---

Top Contributors

[![rkeppner](https://avatars.githubusercontent.com/u/3485765?v=4)](https://github.com/rkeppner "rkeppner (11 commits)")

---

Tags

middlewarelaravelpsr7headersresponse-cache

### Embed Badge

![Health badge](/badges/infusionweb-laravel-middleware-response-cache/health.svg)

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

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[stevenmaguire/laravel-middleware-csp

Provides support for enforcing Content Security Policy with headers in Laravel responses.

39107.6k](/packages/stevenmaguire-laravel-middleware-csp)[dragon-code/laravel-cache

An improved interface for working with cache

6844.8k10](/packages/dragon-code-laravel-cache)[nexxai/laravel-cfcache

A handful of Cloudflare cache helpers for Laravel

1317.7k](/packages/nexxai-laravel-cfcache)

PHPackages © 2026

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