...
Table of Contents |
---|
Use case
Being As it is based on Symfony 2, eZ Platform uses HTTP cache extended with features like content awareness. However, this cache management is only available for anonymous users due to HTTP restrictions.
It is of course possible to make HTTP cache vary thanks to the Vary
response header, but this header can only be based on one of the request headers (e.g. Accept-Encoding
). Thus, to make the cache vary on a specific context (e.g. for example a hash based on a user roles and limitations), this context must be present in the original request.
Feature
As the response can vary on a request header, the base solution is to make the kernel do a sub-request in order to retrieve the user context hash (aka user hash). Once the user hash has been retrieved, it's injected in the original request in the X-User-Hash
custom header, making it possible to vary the HTTP response on this header:
...
Tip | |||||
---|---|---|---|---|---|
| |||||
In cases where you need to deliver content uniquely to a given user, and tricks like using javascript JavaScript and cookie values, hinclude, or disabling cache is not an option. Then remaining option is to vary response by cookie:
Unfortunately this is not optimal as it will by default vary by all cookies, including those set by add trackers, analytics tools, recommendation services, etc. .. However, as long as your application backend does not need these cookies, you can solve this by stripping everything but the session cookie. Example for Varnish can be found in the default VCL examples in part dealing with User Hash, for single-server setup this can easily be accomplished in Apache / Nginx as well. |
...
HTTP cache clear
As eZ Platform uses FOSHttpCacheBundle, this impacts the following features:
- Http HTTP cache purge
- User context hash
Varnish proxy client from FOSHttpCache lib is used for clearing eZ Http HTTP cache, even when using Symfony HttpCache. A single BAN
request is sent to registered purge servers, containing a X-Location-Id
header. This header contains all Location IDs for which objects in cache need to be cleared.
...
FOSHttpCacheBundle User Context feature is used is activated by default.
As the response can vary on a request header, the base solution is to make the kernel do a sub-request in order to retrieve the context (aka user context hash). Once the user hash has been retrieved, it's injected in the original request in the X-User-Hash
header, making it possible to vary the HTTP response on this header:
...
eZ Platform already interferes in with the hash generation process , by adding current user permissions and limitations. One You can also interfere in this process by implementing custom context provider(s).
User hash generation with Varnish 3
Described The behavior described here comes out of the box with Symfony reverse proxy, but it's of course possible ot to use Varnish to achieve the same.
...