Download the PHP package vatia/laravel-varnish without Composer
On this page you can find all versions of the php package vatia/laravel-varnish. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vatia/laravel-varnish
More information about vatia/laravel-varnish
Files in vatia/laravel-varnish
Package laravel-varnish
Short Description Making Varnish and Laravel play nice together
License MIT
Homepage https://github.com/vatia/laravel-varnish
Informations about the package laravel-varnish
Making Varnish and Laravel play nice together
This package provides an easy way to work with Varnish 4 (or 5) in Laravel 5.2 and PHP version >= 7.0.0. It provides a route middleware that, when applied to a route, will make sure Varnish will cache the response no matter what. The package also contains a function to flush the Varnish cache from within the application.
Postcardware
You're free to use this package (it's MIT-licensed), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
The best postcards will get published on the open source page on our website.
Installation
We assume that you've already installed Varnish on your server. If not read this blogpost to learn how to install it.
You can install the package via composer:
First up: registering the service provider:
Next you must publish the config-file with:
This is the contents of the published file:
In the published laravel-varnish.php
config file you should set the host
key to the right value.
Add the Spatie\Varnish\Middleware\CacheWithVarnish
middleware to the route middelwares:
Finally, you should add these lines to the vcl_backend_response
function in your VCL (by default this is located at /etc/varnish/default.vcl
on your server):
We highly recommend using the VCL provided the varnish-5.0-configuration-templates repo made by Mattias Geniar.
Usage
Caching responses
The routes whose response should be cached should use the cacheable
middleware.
The amount of minutes that Varnish should cache this content can be configured in the cache_time_in_minutes
key in the laravel-varnish.php
config file. Alternatively you could also use a middleware parameter to specify that value.
Behind the scenes the middleware will add an X-Cacheable
and Cache-Control
to the response. Varnish will remove all cookies from Laravel's response. So keep in mind that, because thelaravel_session
cookie will be removed as well, sessions will not work on routes were the CacheWithVarnish
middleware is applied.
Clearing cache from Varnish
There's an artisan command to flush the cache. This can come in handy in your deployment script.
You can also do this in your code to flush the cache:
You can clear cache for request url using code below:
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Freek Van der Herten
- All Contributors
About Spatie
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
License
The MIT License (MIT). Please see License File for more information.