caching anon users', & auth users' ESI, content specifically in Laravel PHP framework apps?

spaceman spaceman at
Tue Dec 16 21:08:16 CET 2014

If I were you I would put a filter on the ESI routes that need to be cached 
that prevents the cookie like this:
Route::filter('nocookie', function() {
	Config::set('session.driver', 'array');
The session driver array doesn't set cookies. However if there are client side 
cookies then you will need to strip them using Varnish. I don't know if this 
is correct way but I do it like:
if ( ~ "^(.*\.)?hostname(\..*)?$" ) {
    if ( req.url ~ "^/path/" ) {
        unset req.http.Cookie;
in vcl_recv. This should make the pages cachable by Varnish. You should also 
set the cache control headers using this:
$response->setCache(array('last_modified' => new \DateTime(), 'max_age' => 300 
This can be done in a filter or on the controller, it will need to be a proper 
laravel response object.

On 2014/12/16 09:12:52 , grantksupport at wrote:
>I'm trying to get varnish to cooperate with (a new-installed) laravel php framework's sesion caching (
>Currently, when using redis for session storage, laravel sets a COOKIE -- for both authenticated & anonymous users
>	Cookie: laravel_session=eyJ...UifQ%3D%3D
>For anon users, and for ESI blocks with auth'd users, Varnish should cache.
>What's the correct method for ensuring Varnish caches in these cases, when using a Laravel app?
>Can/should it be handled only in Varnish VCL -- stripping the cookie?  If so, how's the ID of auth vs anon cookie best handled?
>or, must in be done in concert with, or solely within, the Laravel app?
>varnish-misc mailing list
>varnish-misc at

More information about the varnish-misc mailing list