Download the PHP package mnshankar/laravel-cache-route without Composer
On this page you can find all versions of the php package mnshankar/laravel-cache-route. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mnshankar/laravel-cache-route
More information about mnshankar/laravel-cache-route
Files in mnshankar/laravel-cache-route
Package laravel-cache-route
Short Description Cache (HTML) output of entire route to speedup your Laravel application
License MIT
Informations about the package laravel-cache-route
Cache contents of entire route in Laravel
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.
Installation
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.
Usage
Edit your http kernel.php file to include the package like so:
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:
-
In your route:
Using Laravel 5.0
Using Laravel 5.1+
You can continue using Laravel 5.0 style.. or use chaining:
You may also use route groups. Please look up Laravel documentation on Middleware to learn more https://laravel.com/docs/5.2/middleware
Configuration Options
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
Thoughts
Be VERY cautions when using a whole page cache such as this. Remember contents of the cache are visible to ALL your users.
- For, "mostly static" content, go for it!
- For, "mostly dynamic" content or heavily user-customized content, AVOID this strategy. User specific information is gathered server side. So, you essentially WANT to hit the server.
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.