Package Data | |
---|---|
Maintainer Username: | mnshankar |
Maintainer Contact: | mnshankar@gmail.com (Shankar Manamalkav) |
Package Create Date: | 2017-05-26 |
Package Last Update: | 2017-05-26 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:16:53 |
Package Statistics | |
---|---|
Total Downloads: | 85 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 0 |
This is a Laravel 5.0+/PHP 5.4+ package that caches the response to an entire "get" request in the cache so subsequent requests to the same url are speeded up substantially.
Every effort has been made to insure that the package is extremely easy to install and use. After you "require" the package, you are ready to use it! There is no need for setting up service providers, facades, config files etc.
$ composer require mnshankar/laravel-cache-route
Edit your http kernel.php file to include the package like so:
'cache.route'=>'mnshankar\Cache\Middleware\CacheRoute',
Now, use the middleware to cache the HTML output of an entire page either from the controller or from your route like so:
In your controller:
function __construct()
{
$this->middleware('cache.route');
}
In your route:
Using Laravel 5.0
Route::get('my/page', ['middleware' => 'cache-route', function()
{
//
}]);
Using Laravel 5.1+
You can continue using Laravel 5.0 style.. or use chaining:
Route::get('/', function () {
//
})->middleware(['cache-route']);
You may also use route groups. Please look up Laravel documentation on Middleware to learn more https://laravel.com/docs/5.2/middleware
Two configuration options (set via env parameters) are used by the package
Cache TTL (Time-To-Live):
CACHE_TTL=30
This parameter specifies a cache ttl value of 30 minutes
Note that you can always use php artisan cache:flush to clear your application cache
Enable Cache (defaults to true):
CACHE_ENABLE=false
This parameter can be used to turn off caching
Be VERY cautions when using a whole page cache such as this. Remember contents of the cache are visible to ALL your users.
Good rule of thumb: If two different users see different pages on hitting the same URL, DO NOT cache the output using this strategy. An alternative may be to cache database queries.