Varnish 4 how to show pages with cookies from the backend or uncacheable for other reason pages?

0

I'm trying to tune my varnish cache server in order to be able to cache pages with some specific cookies.

However I find it very hard to see if a page is actually cached or not. I know that in varnish I cannot list all the cached URLs, but is it possible to show in real time if pages coming from the backend are being cached or not?
And even more - if they are not cached probably there's a way to find out why?

Because honestly it's very hard to believe that such a complex solution works in the way that you just configure some stuff and then you "hope" it will cache pages, but you have no real way to check if they are being cached or not and (most important) why the decision not to cache the page was taken? And then if page is not cached then you have no idea why and and the only way to find out is by guessing and changing random stuff in the configuration and checking if it will somehow change the cache behavior?

I guess I can monitor the backend requests and if there's no more request to certain URL despite it being opened then the page is cached, but this is really guessing and not actual way to be sure about the status and condition of the page in varnish cache.

Kaloyan Georgiev Mehandzhiyski

Posted 2019-02-19T06:45:14.633

Reputation: 1

Answers

0

You would check whether Varnish is caching pages by looking at X-Varnish HTTP header. How you check headers is either through browser or command line.

Check HTTP headers via browser (e.g. Chrome)

  • Open Chrome Developer console by right clicking anywhere on the page and choosing "Inspect"
  • Head to Network tab. From there choose "Doc" and reload the page in question
  • On the right side you will find Response Headers for the current request. And there you'll find the X-Varnish to be one of the headers.

Check HTTP headers via command line

To check via command line, the common tool is curl. You would run, e.g. curl -IL <URL> and this will nicely show the response headers, right there in terminal. However, this may provide irrelevant results, unless you construct all the required request headers.

How to interpret the value of X-Varnish

If there are two numbers, that means the request comes from cache. If there is one number, that means the request comes from backend.

To check why request was uncached

... There the most straightforward approach is to ammend changes to your VCL in a way that it will emit custom headers stating the reason why requests are bypassing cache.

Danila Vershinin

Posted 2019-02-19T06:45:14.633

Reputation: 113

I use curl to headers and I also monitor backend responses during opening a page to see if it's cached or not.

However I still have troubles identifying

  1. The reason the page is dropped from cache a lot sooner than the TTL says (even after removing all headers from the backend server).
  2. Reason for not caching the page at all sometimes.
  3. < – Kaloyan Georgiev Mehandzhiyski – 2019-03-09T07:11:03.273