Thanks for your contribution.

I am thinking about this for a long time, but the problem is Varnish won't cache content if it has cookie, so for an authenticated user, if we want share the cached html with anonymous users, we need to unset the cookie if there is, but some esi blocks won't work well if we did this.

Is there a way to implement this?
Thanks,
-Robbin

Comments

mikeytown2’s picture

Title:Is there an way to cache html (not esi blocks) for authenticated user?» ESI Varnish Configuration: Cache html chunks in varnish for authenticated users? (cookie issue)
Version:6.x-1.0-beta1» 6.x-2.x-dev
Component:Code» Documentation
Category:feature» support

This is not as big of an issue now that ESI (6.x-2.x) can use the built in page cache. This deals with varnish configuration.

djbobbydrake’s picture

When you say "ESI (6.x-2.x) can use the built in page cache", if the session cookie isn't unset, we're still not retrieving the cache from Varnish, correct? Can you explain more "This deals with varnish configuration." How can I configure Varnish to serve a cached page (when I say cached, I mean by Varnish, not the Drupal page cache) to an authenticated user, while still having ESI blocks work that display stuff such as the user's username?

mikeytown2’s picture

Go to admin/settings/esi and under "Global Settings" enable "Use Core's page cache to store ESI fragments." This is the quick and dirty way to get it working without changing your varnish configuration.

For a more in-depth look checkout http://www.lullabot.com/articles/varnish-multiple-web-servers-drupal and look for the code block that contains set req.http.Cookie = ";" + req.http.Cookie;; read up on that section.

Once you have a good understanding of that you need to checkout the esi_blocks-2_0.vcl file. You might want to change "USER" to 2 and "ROLE" to 1 in that code.

Documentation is lacking, so documenting the steps you had to take in order to get it working would be helpful for everyone :)

djbobbydrake’s picture

What's the benefit of serving ESI fragments from Core's page cache vs from Varnish? Wouldn't it be faster to serve the ESI fragments from Varnish?

mikeytown2’s picture

Varnish is faster, but it can be complicated to setup. If you're asking why core's page cache is used at all, ESI does support AJAX loading.

kentr’s picture

I am thinking about this for a long time, but the problem is Varnish won't cache content if it has cookie, so for an authenticated user, if we want share the cached html with anonymous users, we need to unset the cookie if there is, but some esi blocks won't work well if we did this.

Not sure I'm understanding correctly, so this comment may not apply:

Varnish can cache items that have a cookie. Change the vcl file to allow this. Example here.