How can I check the reason why varnish did not cache a response?

Solution 1:

Adapt and add this to your vcl, in sub vcl_fetch. Mostly, not hitting is a result of a cookie in the request when it leaves your vcl_recv config.

    # Section sets http return headers, for caching diagnosis
     if (!beresp.ttl > 0s) {
              set beresp.http.X-Cacheable = "NO:Not-Cacheable";

        if (req.http.Cookie && req.http.Cookie ~ "wordpress_") { set beresp.http.X-Cacheable = "NO:Authed-user"; }
        elseif (req.http.Cookie && req.http.Cookie ~ "PHPSESSID") { set beresp.http.X-Cacheable = "NO:PHP-SESS"; }
        elseif (req.http.Cookie && req.http.Cookie ~ "vendor_re") { set beresp.http.X-Cacheable = "NO:vendor-region"; }
        elseif (req.http.Cookie && req.http.Cookie ~ "themetype2") { set beresp.http.X-Cacheable = "NO:themetype2"; }
        elseif (req.http.X-Requested-With == "XMLHttpRequest") { set beresp.http.X-Cacheable = "NO:Ajax"; }
        return(hit_for_pass);
    }

You will probably need to adapt that. But, you can then see those X-Cacheable headers in the site.