4

Currently I manage to configure varnish to cache items from 1 user, but the when the second users comes in varnish fetch another asset from Apache.

How can I cache static assets behind magento ( css, js , image pdf etc ) accessible from multiple users ?

On vcl_recv, I've configured :

   if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
        unset req.http.Https;
        unset req.http.Cookie;
        return (lookup);
    }

On vcl_fetch :

if (beresp.status == 200 || beresp.status == 301 || beresp.status == 404) {
if (beresp.http.Content-Type ~ "text/html" || beresp.http.Content-Type ~ "text/xml") 
{
    # do something
} else {
    unset beresp.http.expires;
    unset beresp.http.set-cookie;
    set beresp.ttl = 300h;
}

I suspect this this has something to do vcl_hash that store the cache with some kind of client's fingerprint.

Is there a way to manipulate the way it hash only for certain asset types ?

EDIT 1: Full config : http://pastebin.com/mzSVpEqN

Rianto Wahyudi
  • 493
  • 3
  • 11

3 Answers3

1

As noted in the comments, comment out the vcl_hash function (provided you don't need it for anything else) and hopefully you should see improvements.

HTH!

KM.
  • 1,746
  • 2
  • 18
  • 31
0

I found out the way to solve this.

Varnish store different cached page for each specific User-Agent. I found the following technique to normalize user agent ( https://www.varnish-cache.org/trac/wiki/VCLExampleNormalizeUserAgent )

I just put everything into 1 basket and see huge increase in the number of hits.

On vcl_recv:

if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
     set req.http.user-agent = "Mozilla";
     unset req.http.Https;
     unset req.http.cookie;
     return (lookup);
}
Rianto Wahyudi
  • 493
  • 3
  • 11
0

Varnish will honor Vary headers from the backend. Unless the backend sends Vary: User-Agent, there's no reason to normalize the User-Agent client header.