PHPackages                             sevenlab/laravel-responsecache - 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. sevenlab/laravel-responsecache

ActiveLibrary[Caching](/categories/caching)

sevenlab/laravel-responsecache
==============================

Cache responses in a Laravel application

2.3.0(12mo ago)11.4k↓100%MITPHPPHP ^7.0|^8.0CI failing

Since Oct 12Pushed 12mo ago2 watchersCompare

[ Source](https://github.com/SevenLabnl/laravel-responsecache)[ Packagist](https://packagist.org/packages/sevenlab/laravel-responsecache)[ Docs](https://github.com/sevenlabnl/laravel-responsecache)[ RSS](/packages/sevenlab-laravel-responsecache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (15)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b16c3be85c6dc9dec53fdf3f6fdea43695f054ab397d2ae8b68e3ff2bcf63310/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f536576656e4c61622f6c61726176656c2d726573706f6e736563616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/SevenLab/laravel-responsecache)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/c46d173e483ed5e0c068e89e025155ed3cdb241fe58ecbab4f3980a8952de17a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f536576656e4c61622f6c61726176656c2d726573706f6e736563616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/SevenLab/laravel-responsecache)

Cache responses
===============

[](#cache-responses)

This Laravel package can cache an entire response. By default it will cache all successful GET-requests for a week. This could potentially speed up the response quite considerably.

So the first time a request comes in the package will save the response before sending it to the users. When the same request comes in again we're not going through the entire application but just respond with the saved response.

The package is based on [spatie/laravel-responsecache](https://github.com/spatie/laravel-responsecache) but uses the defined [route names](https://laravel.com/docs/routing#named-routes) so the cached responses can easily be cleared without having to clear the whole cache.

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

[](#installation)

You can install the package via Composer:

```
composer require sevenlab/laravel-responsecache
```

The package will automatically register itself.

You can publish the config file with:

```
php artisan vendor:publish --provider="SevenLab\ResponseCache\ResponseCacheServiceProvider"
```

This is the contents of the published config file (`config/responsecache.php`):

```
return [

    /*
     * Determine if the response cache middleware should be enabled.
     */
    'enabled' => env('RESPONSECACHE_ENABLED', true),

    /*
     * Specify the tag name that will be used for the cache.
     */
    'tag' => env('RESPONSECACHE_TAG', 'responsecache'),

];
```

And finally you should install the provided middlewares in the HTTP kernel (`app/Http/Kernel.php`).

```
...

protected $routeMiddleware = [
    ...
    'cacheResponse' => \SevenLab\ResponseCache\Middleware\CacheResponse::class,
    'doNotCacheResponse' => \SevenLab\ResponseCache\Middleware\DoNotCacheResponse::class,
];

...
```

Usage
-----

[](#usage)

By default it will cache all successful GET-requests for a week. Logged in users will each have their own separate cache.

### Caching specific routes

[](#caching-specific-routes)

When using the route middleware you can specify the number of minutes these routes should be cached:

```
// cache this route for 5 minutes
Route::get('/my-special-snowflake', 'SnowflakeController@index')->middleware('cacheResponse:5');

// cache all these routes for 10 minutes
Route::group(function() {
   Route::get('/another-special-snowflake', 'AnotherSnowflakeController@index');

   Route::get('/yet-another-special-snowflake', 'YetAnotherSnowflakeController@index');
})->middleware('cacheResponse:10');
```

### Preventing a route from being cached

[](#preventing-a-route-from-being-cached)

Requests can be ignored by using the `doNotCacheResponse`-middleware. This middleware [can be assigned to routes and controllers](http://laravel.com/docs/master/controllers#controller-middleware).

Using the middleware on a route:

```
Route::get('/auth/logout', 'AuthController@getLogout')->name('auth.logout')->middleware('doNotCacheResponse');
```

Alternatively you can add the middleware to a controller:

```
class AuthController extends Controller
{
    public function __construct()
    {
        $this->middleware('doNotCacheResponse', ['only' => ['getLogout']]);
    }
}
```

### Clearing specific routes

[](#clearing-specific-routes)

Specific routes can be cleared with:

```
ResponseCache::forget(['auth.logout']);
```

The same can be accomplished by issuing this artisan command:

```
php artisan responsecache:forget auth.logout
```

### Clearing all routes

[](#clearing-all-routes)

The entire cache can be cleared with:

```
ResponseCache::clear();
```

This will clear everything from the cache store specified in the config-file (`config/cache.php`) with the tag specified in the responsecache-file (`config/responsecache.php`).

The same can be accomplished by issuing this artisan command:

```
php artisan responsecache:clear
```

Credits
-------

[](#credits)

- [Joey Houtenbos](https://github.com/JoeyHoutenbos)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](https://github.com/SevenLabnl/laravel-responsecache/contributors)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance50

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~200 days

Recently: every ~317 days

Total

13

Last Release

363d ago

Major Versions

0.0.1 → 1.0.22018-10-12

1.5.0 → 2.0.02023-01-09

PHP version history (2 changes)0.0.1PHP ^7.0

1.5.0PHP ^7.0|^8.0

### Community

Maintainers

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

---

Top Contributors

[![JoeyHoutenbos](https://avatars.githubusercontent.com/u/1810441?v=4)](https://github.com/JoeyHoutenbos "JoeyHoutenbos (15 commits)")[![Mezeman1](https://avatars.githubusercontent.com/u/22822736?v=4)](https://github.com/Mezeman1 "Mezeman1 (2 commits)")[![SevenLab-nl](https://avatars.githubusercontent.com/u/26413816?v=4)](https://github.com/SevenLab-nl "SevenLab-nl (2 commits)")[![nielskramerr](https://avatars.githubusercontent.com/u/12908597?v=4)](https://github.com/nielskramerr "nielskramerr (1 commits)")

---

Tags

laravelresponsecacheresponselaravelcachelaravel-responsecachesevenlabresponsecache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sevenlab-laravel-responsecache/health.svg)

```
[![Health](https://phpackages.com/badges/sevenlab-laravel-responsecache/health.svg)](https://phpackages.com/packages/sevenlab-laravel-responsecache)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[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)[flc/laravel-middleware-cache-response

Laravel中间件-Response缓存

608.2k](/packages/flc-laravel-middleware-cache-response)[arifhp86/laravel-clear-expired-cache-file

Remove laravel expired cache file/folder

36128.7k](/packages/arifhp86-laravel-clear-expired-cache-file)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)[salehhashemi/laravel-configurable-cache

Configurable Laravel cache manager

2114.5k1](/packages/salehhashemi-laravel-configurable-cache)

PHPackages © 2026

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