Caching cookies with Varnish 4

Raymond Gonzalez raygo22 at gmail.com
Wed May 13 17:33:34 CEST 2015


I want to be able to cache pages that have a cookie. Let's say I have a
cookie called "testcookie" that I set up with php.

If testcookie = 1 I want a page (cached), if testcookie = 2 it will have a
different page ( i want to cache it) , and like that N times. This is my
current varnish vcl

____________


vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}



sub vcl_hash {
hash_data(regsub(req.http.Cookie,"^.*?testvarnish=([^;]*);*.*$" , "\1"));
}

sub vcl_recv {
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't
need,
    # rewriting the request, etc.

}

sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.
    #
    # Here you clean the response headers, removing silly Set-Cookie headers
    # and other mistakes your backend does.

}

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
    # You can do accounting or modifying the final object here.
}

________________

Any idea? Thanks!

-- 
Raymond Gonzalez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20150513/da87e5a1/attachment.html>


More information about the varnish-misc mailing list