wiki:VCLExampleCachingLoggedInUsers

Version 2 (modified by kane, 5 years ago) (diff)

--

Caching logged in users

One of the hardest things to get right when caching, is to be able to cache content for logged in or cookied users.

The below snippets of code show you how to do this with varnish, using vcl_hash and esi.

Here is what you need in your setup to make this work:

  • A value in your cookie that unique defines your user.
    • This can be a session key if you let your cache expire
    • This should be a UUID if you do not let your cache expire, but purge manually instead.
  • A predictable identifier in your esi calls to indicate what content is state specific, and which is not
    • This let's varnish do the right thing, without needing to know anything about your application
    • Since you control the ESI urls, and the user never sees them, any markers are safe