Disabled - Do not use ESI.
Not Cached - Use ESI, but never cache the content.
Global - Content is same on every page.
Page - Content changes based on the URL.
User Role - Content changes based on the user role.
User Role/Page - Content changes based on the user role as well as the URL.
User ID - Content changes based on the UID; otherwise it is the same as global.

Comments

brianmercer’s picture

Are these things that can already be done with Panels variants?

mikeytown2’s picture

I'm following blocks on this; I have blocks working currently and I'm working on getting this flying with panels. Having fine grained control over how the cached content behaves in varnish/nginx/browser is important.

mikeytown2’s picture

Status: Active » Fixed
StatusFileSize
new29.53 KB

This code has been committed

mikeytown2’s picture

StatusFileSize
new3.55 KB

This has been committed as well

brianmercer’s picture

I'm not sure this is the intended use of the "Cache-Control: private" header.

I interpret http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html to say that a shared cache like Varnish or nginx should not cache a private response, but that a single user cache, like a browser cache, may cache it.

Right now your User Role and User ID settings are sending "Cache-Control: private, max-age=$max_age" which might as well be "Cache-Control: no-cache" to nginx because nginx interprets private as no-cache.

I see you're using it in your VCL, but nearly all the VCLs I can find on the web interpret private as no-cache. https://www.varnish-cache.org/trac/ticket/477

mikeytown2’s picture

Sounds like this needs some more thought... any ideas on how to accomplish the per user and per role cache? I haven't looked into the details of how this works currently in ESI so there could be a nice solution to the problem; just seeing what options are available.

Controlling what esi_add_cache_headers() does sounds like it might need to be abstracted depending on the solution we come up with, as what is in there now works great for AJAX.

brianmercer’s picture

The nginx cache key is configurable but usually includes the request uri like a typical Varnish cache key so these would work:

/esi/panels_pane/mytheme:7:37/SESSlkas98f987sdf987sd987f8d97sfsd87f987
/esi/panels_pane/mytheme:7:37/RSESSlkas98f987sdf987sd987f8d97sfsd87f987
/esi/panels_pane/mytheme:7:37/PATH=node/2343

The sample VCLs that come with ESI add the session to the cache key from the cookie, which could be done in nginx also, though uri would be easier. Some Varnish docs suggest the cookie method also: https://www.varnish-cache.org/trac/wiki/VCLExampleCachingLoggedInUsers They may assume that it's easier to do this way with some VCL than to add it into the uri from the application code.

The ESI sample VCL does the same thing for roles with a cookie beginning with RSESS with a hash of a set of roles. For some reason I'm not getting that cookie. Also "Pass the current url to the external url as a base64 encoded string" doesn't seem to do anything. I've only tried them with Panels.

mikeytown2’s picture

"Pass the current url to the external url as a base64 encoded string"
This only works if you set an external URL in the textfield. Our setup is a blend of Drupal & .Net; being able to pull in external resources (not in Drupal) like this is important for us. If there is a standard for passing context that would be nice to follow; otherwise I'll be creating my own.

If you set the scope to "page" the base64 version of the URL should be added to the ESI request; which will then get decoded and turned into $_GET['q']

mikeytown2’s picture

StatusFileSize
new8.48 KB

I'm a little hesitant about adding the Cache ID to the URL; so I'm thinking it will be an option that one can configure.

In the mean time I've modified the AJAX code to correctly replace CACHE=* with the ID from the cookie. This means that logging in/out with AJAX enabled will no longer cause issues as the browser cache could have had the wrong version of that bit of content. The patch attached does this and has been committed.

mikeytown2’s picture

StatusFileSize
new7.1 KB

This patch has been committed. Allows for CACHE=* to be fully set or as a dynamic replacement (default).

brianmercer’s picture

Looks good. I'm having a problem with my nginx config looping when using cached esi snippets. I have to work that out before I can test the new settings.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.