How to make Varnish ignore, not delete cookies

639

By default Varnish doesn't cache requests with a Cookie header:

http://varnish-cache.org/svn/trunk/varnish-cache/bin/varnishd/default.vcl

  sub vcl_recv {
(...)
  if (req.http.Authorization || req.http.Cookie) {
        /* Not cacheable by default */
        return (pass);
    }
    return (lookup);

You need to code the behaviour you want into the configuration. Be aware that the Cookie is part of the client request, not the "page" (object, really). The "page" (object) comes with a "Set-Cookie" header - that's the one that will be cached.

Also, "Vary: Cookie" doesn't mean "do not cache". It means cache one object for every value of Cookie received.

If your application doesn't generate any content based on Cookie, it's probably safe to ignore it:

-      if (req.http.Authorization || req.http.Cookie) {
+      if (req.http.Authorization) {

Do some tests and you will get the hang of it. Hope this helps.

Share:
639

Related videos on Youtube

April
Author by

April

Updated on September 18, 2022

Comments

  • April
    April almost 2 years

    I have a UITableView of which datasource is core data. The core data has one entity with two attributes i.e. textValue, textCreationDate.

    I'm able to fetch these values in UITableView as textValue in cell.textLabel.text and textCreationDate in cell.detailTextLabel.text

    NSManagedObject *copies = [self.databaseArray objectAtIndex:indexPath.row];
    cell.textLabel.text = [copies valueForKey:@"textcopied"];
    cell.detailTextLabel.text = [copies valueForKey:@"datecopied"];
    

    Now I want to divide this table into sections and sections should be created using textCreationDate. For example, I have 5 values in textValue with 3 of today's date and 2 of yesterday's date. This should divide the tableView into 2 sections and put textValues into corresponding sections.

  • Jason Christa
    Jason Christa over 13 years
    Ok this is starting to make more sense now. I definitely don't want to cache responses with the set-cookie header because things like the CSRF token get set there.
  • Jason Christa
    Jason Christa over 13 years
    Also can I use the Vary: Cookie header a signal not to try to cache the page. If you had 10,000 active users, caching a page for each of them is probably a waste of space.
  • Thiago Figueiro
    Thiago Figueiro over 13 years
    If you don't want the page to be cached for each user have the application return "Cache-Control: private"