0

I have a page that have a content that will be displayed to all users, but the issue is I have an ajax call done after page load this call is not cacheable but it requires cookies which is removed from the cached page, what can I do to to keep the cookies and still get the cached page?

Mustafa Abuelfadl
  • 537
  • 1
  • 4
  • 20
  • Postin it for the second time :P Are you aware of this https://www.varnish-cache.org/trac/wiki/VCLExampleCacheCookies – Tamil Jul 28 '12 at 15:39
  • I read that and I'm fully aware that it can be done by adding cookies to hash but it will result to have a per user cache, this is not what I want to accomplish cause there is no gain via this method - actually there is a little gain but not noticable. – Mustafa Abuelfadl Jul 28 '12 at 15:44
  • Please, paste your `vcl` contents – Vitalii Zurian Aug 26 '12 at 13:22

1 Answers1

1

In vcl_hash routine you can decide exactly how to hash your requests. For instance the following would only hash on the request URI and not include cookies:

sub vcl_hash {
    set req.hash += req.url;
    set req.hash += req.http.host;
} 

Do note that you probably want to exclude the ajax call and any other requests that are not cacheable in your configuration. Or even better, let the backend send a header if the request is cacheable and let varnish act on that.

Just beware of caching pages with setcookie and it should be alright.

Clarence
  • 2,944
  • 18
  • 16