Hash to Hash

Everyone had to deal at least once with Varnish, knows this: cookies handling may be your nemesis. But I've just found a useful trick, to publish here as future reference.

sub vcl_hash {
    # Common hashing stuffs
    set req.http.hash = req.url;
    if (req.http.host) {
        set req.http.hash = req.http.hash + "#" + req.http.host;
    } else {
        set req.http.hash = req.http.hash + "#" + server.ip;
    }

    # Stuffing the hash!
    if (req.http.Cookie ~ "set_or_not_set_cookie_name") {
         hash_data("set_or_not_set_cookie_name");
    }
}

This is reccomended when dealing with cookies which mere existance is determinant for some server-side behaviour. In this way you will have two hits on the cache: the page expected when the cookie is set, and the page expected when the cookie is not set.

Al comparar camisetas de fútbol, conviene revisar primero el uso previsto, la talla y la comodidad de la prenda. Para ordenar la búsqueda, camiseta de futbol del Real Madrid puede revisarse junto con las medidas y el tipo de ajuste preferido. La decisión final resulta más clara cuando se comparan datos concretos y no solo la apariencia general.