spatie / laravel-responsecache
Speed up a Laravel application by caching the entire response
Fund package maintenance!
spatie
spatie.be/open-source/support-us
Installs: 7 859 640
Dependents: 52
Suggesters: 0
Security: 0
Stars: 2 725
Watchers: 40
Forks: 239
Open Issues: 0
pkg:composer/spatie/laravel-responsecache
Requires
- php: ^8.4
- illuminate/cache: ^12.0
- illuminate/console: ^12.0
- illuminate/container: ^12.0
- illuminate/http: ^12.0
- illuminate/support: ^12.0
- nesbot/carbon: ^3.0
- spatie/laravel-package-tools: ^1.9
Requires (Dev)
- larastan/larastan: ^3.9
- laravel/framework: ^12.0
- laravel/pint: ^1.13.7
- mockery/mockery: ^1.6
- orchestra/testbench: ^10.0
- pestphp/pest: ^4.0
- dev-main
- 8.1.0
- 8.0.0
- 7.7.2
- 7.7.1
- 7.7.0
- 7.6.5
- 7.6.4
- 7.6.3
- 7.6.2
- 7.6.1
- 7.6.0
- 7.5.2
- 7.5.1
- 7.5.0
- 7.4.10
- 7.4.9
- 7.4.8
- 7.4.7
- 7.4.6
- 7.4.5
- 7.4.4
- 7.4.3
- 7.4.2
- 7.4.1
- 7.4.0
- 7.3.1
- 7.3.0
- 7.2.0
- 7.1.0
- 7.0.1
- 7.0.0
- 6.6.9
- 6.6.8
- 6.6.7
- 6.6.5
- 6.6.4
- 6.6.3
- 6.6.2
- 6.6.1
- 6.6.0
- 6.5.0
- 6.4.0
- 6.3.0
- 6.2.1
- 6.2.0
- 6.1.1
- 6.1.0
- 6.0.2
- 6.0.1
- 6.0.0
- v5.x-dev
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.4.5
- 4.4.4
- 4.4.3
- 4.4.2
- 4.4.1
- 4.4.0
- 4.3.0
- 4.2.1
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- v3.x-dev
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- v2.x-dev
- 2.0.0
- v1.x-dev
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- 0.0.1
- dev-upgrade/php85-laravel12
- dev-forget-all-users
This package is auto-updated.
Last update: 2026-02-16 16:44:59 UTC
README
Speed up an app by caching the entire response
This Laravel package can cache an entire response. By default it will cache all successful GET requests that return text based content (such as HTML and JSON) for a week. This could potentially speed up the response quite considerably.
The first time a request comes in, the package will save the response before sending it to the user. When the same request comes in again, the cached response is returned without going through the entire application.
Here's a quick example:
use Spatie\ResponseCache\Middlewares\CacheResponse; Route::middleware(CacheResponse::for(minutes(10)))->group(function () { Route::get('/posts', [PostController::class, 'index']); Route::get('/posts/{post}', [PostController::class, 'show']); });
For pages where brief staleness is acceptable, you can use flexible caching. After the lifetime expires, the stale response is still served instantly while the cache refreshes in the background. Once the grace period is over, the cache is considered expired and the next request will be fully recalculated:
use Spatie\ResponseCache\Middlewares\FlexibleCacheResponse; Route::get('/dashboard', [DashboardController::class, 'index']) ->middleware(FlexibleCacheResponse::for(lifetime: hours(1), grace: minutes(5)));
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Documentation
All documentation is available on our documentation site.
Testing
You can run the tests with:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.