Varnish - PURGE request does not clear hash_data () URL

In vcl_hash I have

backend default {
        .host = "127.0.0.1";
        .port = "8080";
}
acl purge {
        "localhost";
}
sub vcl_hash {
        if(req.http.Cookie ~ "isLogin") {
                hash_data("1");
        }
}
sub vcl_recv {
        if (req.request == "PURGE") {
                if (!client.ip ~ purge) {
                        error 405 "Not allowed.";
                }
                return (lookup);
        }
        return(lookup);
}
sub vcl_hit {
        if (req.request == "PURGE") {
                purge;
                error 200 "Purged.";
        }
}
sub vcl_miss {
        if (req.request == "PURGE") {
                purge;
                error 404 "Not in Cache.";
        }
}

I use the command below to clear urls. curl -X PURGE http://release.com/user/details

If the URL is cached for registered users, I get below

curl -X PURGE http://release.com/user/details
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>200 Purged.</title>
  </head>
  <body>
    <h1>Error 200 Purged.</h1>
    <p>Purged.</p>
    <h3>Guru Meditation:</h3>
    <p>XID: 1071483546</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>

If it is cached only for registered users, I continue to get below the result. (Although url does "Hits")

curl -X PURGE http://release.com/user/details
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>404 Not in Cache.</title>
  </head>
  <body>
    <h1>Error 404 Not in Cache.</h1>
    <p>Not in Cache.</p>
    <h3>Guru Meditation:</h3>
    <p>XID: 998719206</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>

http://release.com/user/details looks different based on if the user is logged in or not. (i.e. has a cookie isLogin or not). PURGE does not work for URLs that hashed in vcl_hash. It seems to be a mistake or a feature of varnish. Please suggest what can be done.

+4
2

, , , , vcl_hash . , , , . cookie if(req.http.Cookie ~ "isLogin"), cookie , :

curl -X PURGE --cookie "isLogin=1" http://release.com/user/details

, , cookie .

0

. ( User-Agent).

. (Vary) . .

, beresp.http.Vary ( ).

Vary, ( Google), , User-Agent. vcl_deliver.

sub vcl_recv {
  ...

  if (req.restarts == 0) {
    # Change this code, we are using a CloudFront header
    if (req.http.CloudFront-Is-Mobile-Viewer == "true") {
      set req.http.X-Device-Type = "mobile";
    } else {
      set req.http.X-Device-Type = "desktop";
    }
  }

  ...

  if (req.method == "PURGE") {
    if (!client.ip ~ acl_purge) {
      return(synth(400, "Bad request."));
    }
    return(purge);
  }

  ...
}

sub vcl_backend_response {
    ...

    if (beresp.http.Vary) {
      set beresp.http.Vary = beresp.http.Vary + ", " + "X-Device-Type";
    } else {
      set beresp.http.Vary = "X-Device-Type";
    }

    ...
}

sub vcl_deliver {
  ...

  set resp.http.Vary = "Accept-Encoding, User-Agent";

  ...
}
0

All Articles