First request is always a miss (per client)

Laurence Rowe l at lrowe.co.uk
Mon Nov 22 18:54:29 CET 2010


While Pressflow itself may not set cookies, with google analytics or
similar you'll see the cookies set by its javascript. I've used
something like this in the past to normalize cookies:

    if (req.http.Cookie) {
      # Simplify tokenization
      set req.http.Cookie = "; " req.http.Cookie;
      # Remove osas and google analytics cookies
      set req.http.Cookie = regsuball(req.http.Cookie, ";
(osas_id|__utm.)=[^;]*", "");
      # Finally remove cookie header if it is now empty
      if (!req.http.Cookie ~ "[^ ;]") {
        remove req.http.Cookie;
      } else {
        # Remove the leading delimiter
        set req.http.Cookie = regsub(req.http.Cookie, "^; ", "");
      }
    }

Laurence


On 19 November 2010 06:50, Kristian Lyngstol
<kristian at varnish-software.com> wrote:
> On Thu, Nov 18, 2010 at 05:38:24PM +0100, Frederik Schumacher wrote:
>> I'm running a Pressflow site on a LAMP with Apache on port 8080 and
>> Varnish on port 80. My problem is, that the very first request from
>> any client is always a miss, this even happens on the same machine -
>> using for example Firefox for the first request (miss), then curl -I
>> (miss), then Firefox (hit), then curl -I (hit). Every request after
>> that is a cache hit. Let's say I request "localhost/foo" using Firefox
>> and it's a miss (and then gets cached), shouldn't "curl -I
>> http://localhost/foo" right after that be a hit? Is this expected
>> behavior, or a mis-configuration?
>
> The objects are most likely being cached independently. The most likely
> suspect is the headers you Vary on. For pressflow, I believe that will be
> Cookie and Accept-Encoding by default. If those are not normalized in
> Varnish you will cache one object for each variation (hence Vary:) of the
> client-provided Accept-Encoding and Cookie headers.
>
> Since pressflow doesn't send cookies for anonymous users, that only really
> leaves accept-encoding - which is the most common header you have to
> normalize anyway.
>
> Take a look at the example on the wiki [1] for more discussion, and look
> for a Vary header in the response from your web server.
>
> [1] http://www.varnish-cache.org/trac/wiki/VCLExampleNormalizeAcceptEncoding
>
> --
> Kristian Lyngstøl
> Product Specialist, Varnish Software
> Training and Commercial services:
> http://www.varnish-software.com
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iQEcBAEBAgAGBQJM5h4lAAoJEIC1IG5rXEfqsNAIAJxrQBKqk9Z32575aS8npYra
> x2CzjT3Qzk9zaXfezVtBYgwCuazzV/A3kq5yj+XgydI6woh5rWwCDnbKB/d15e60
> 1ygAjEiW5DKMPj+4e/3svWHVm2DA1no5cNhn45tM3y/vm1LM+ytctNcgQKWDKS2v
> hxX1cMsEAQC30FdZ0DZqD/dCa4Kq2q7ySDxQty/F2VjFkVTONvzrauE8l/Q1mN2X
> z7J2HEjIp0DW/3WQ9IJ46MwjeoQxaq7Z/NgtF0I0TlOfLlv3imk2x+c0kgrPaBvE
> UEZLy9HW75Kp4YcKYbUDLfqj88XkN75oZY4lIwECpodGNy7Mt0ZXKmBSZ7Hg7i8=
> =WXrp
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> http://lists.varnish-cache.org/mailman/listinfo/varnish-misc
>




More information about the varnish-misc mailing list