Route response caching for Laravel
MIT License
Response Cache for Laravel provides an easy way for route responses to be cached, handling the storage and retrieval of the response as well as the necessary headers to utilize client-side browser caching.
Installation Configuration Usage Release Notes Version Compatibility License
composer.json
file.
Command Line:
composer require wowe/laravel-response-cache:1.0.*
Edit Manually:
"require": {
"wowe/laravel-response-cache": "1.0.*"
}
composer update
app.php
config file.'Wowe\Cache\Response\ServiceProvider'
The configuration file may be published to the config
directory by using the command:
php artisan config:publish wowe/laravel-response-cache
This is recommended since the configuration file that comes with the installation can be overridden by an update.
Available Settings
enabled
(boolean)
life
(integer)
global
(boolean)
###Simple Setup###
For a simple site you may cache all responses generated by routes using the GET
method by setting the global
config setting to true
. To adjust how long these responses will be cached just change the value of the life
config setting.
###Advanced Setup### For projects where you need more control over which route responses are cached you may use the available route actions:
cache
'cache'
is set on the action as a string then it is equivalent to 'cache' => true
and will cache the route's response.'cache' => true
is set on the action then the route's response will be cached.'cache' => false
is set on the action then the route's response will not be cached.'cache' => 90
), then the route's response will be cached for that many minutes.no-cache
'cache' => false
and should be set as a string on the action. It cannot accept any value and should not appear in the action as a key.###Examples:###
// No value
Route::get('foo', ['FooController@getFoo', 'cache']);
// True
Route::get('bar', ['FooController@getBar', 'cache' => true]);
// Integer, will cache for 90 minutes
Route::get('baz', ['FooController@getBaz', 'cache' => 90]);
// Group
Route::group(['cache'], function () {
Route::get('qux', 'FooController@getQux');
});
// No value
Route::get('foo', ['FooController@getFoo', 'no-cache']);
// False
Route::get('bar', ['FooController@getBar', 'cache' => false]);
// Group
Route::group(['no-cache'], function () {
Route::get('qux', 'FooController@getQux');
});
Additional information can be found in the CHANGELOG.md file
Laravel | Response Cache |
---|---|
4.2.x | 1.0.x |
The Route Response for Laravel package is open-sourced software licensed under the MIT license