0

I added to varnish config

sub vcl_fetch {

   set beresp.do_esi = true; 

}

}

In my mvc application I've a childaction

<div>@* this should not be cached, I change the returned value in my DB *@
        1 @Html.Action("GetHour", "Index", new { id = 5 })
    </div>

    <div>
        2
        <esi:include>@* this should be cached *@
            @Html.Action("GetHour", "Index", new { id = 5 })
        </esi:include>
    </div>

And added a Request header

Request.Headers.Add("X-Esi", "1");

But Varnish keeps caching entire page.

What do I miss? I've notice in my browser the request header X-Esi doesn't exist. Also Varnish remove properly the tag <esi:include

The code in action GetHour is pretty simple, just retrieve a decimal from SQL Server.

ramires.cabral
  • 910
  • 4
  • 13
  • 28
  • I do not think that you can place content inside an esi:include tag and expect this to be cached. You need to specify a src attribute on an esi:include tag: – Ronald Aug 27 '15 at 06:11
  • If you do not want a page to be cached you should specify a Cache-Control header with a max-age or an s-maxage of 0 to tell varnish not to cache – Ronald Aug 27 '15 at 06:13
  • You're right. Change to and configure ttl to 0 and works. Thanks. – ramires.cabral Aug 27 '15 at 14:57

1 Answers1

1

Change this:

<esi:include>@* this should be cached *@
        @Html.Action("GetHour", "Index", new { id = 5 })
    </esi:include>

for this:

<esi:include src="/Index/GetHour/5">
          </esi:include>

And add to Varnish default.vcl:

sub vcl_fetch {
   set beresp.do_esi = true;

  if(bereq.url ~ "/Index/GetHour"){
    set beresp.ttl = 0s;
  }
}

This was partially answered by @ronald in comments above. Had to remove the [ChildActionOnly] annotation also.

ramires.cabral
  • 910
  • 4
  • 13
  • 28