Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   eZ Publish 4.x / legacy

 
eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Skip to end of metadata
Go to start of metadata

If you are looking for 5.2/5.3 Context aware HTTP cache, see the page Context aware HTTP cache in eZ Publish 5.2-5.3

This feature is available as of eZ Publish 5.2

Use case

Being based on Symfony 2, eZ Publish 5 uses HTTP cache from version 5.0 extended with 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. 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:

This solution is implemented in Symfony reverse proxy (aka HttpCache) and is also accessible to dedicated reverse proxies like Varnish.

Note that sharing ESIs across SiteAccesses is not possible by design (see EZP-22535 - Cached ESI can not be shared across pages/siteaccesses due to "pathinfo" property Closed for technical details)

Vary by User

In cases where you need to deliver content uniquely to a given user, and tricks like using 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, ... However as long as your application backend does not need these cookies, you can solve this by stripping everything but 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

5.4 / 2014.11

As of v5.4 / v2014.11, usage of FOSHttpCacheBundle has been introduced, impacting the following features:

  • Http cache purge
  • User context hash

Varnish proxy client from FOSHttpCache lib is now used for clearing eZ 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.

Symfony reverse proxy

Symfony reverse proxy (aka HttpCache) is supported out of the box, all you have to do is to activate it.

Varnish

User context hash

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:

Name of the user hash header is configurable in FOSHttpCacheBundle. By default eZ Publish sets it to **X-User-Hash**.

 

This solution is implemented in Symfony reverse proxy (aka HttpCache) and is also accessible to dedicated reverse proxies like Varnish.

Workflow

User hash generation

eZ Publish already interferes in the hash generation process, by adding current user permissions and limitations. One can also interfere in this process by implementing custom context provider(s).

User hash generation with Varnish 3

Described behavior comes out of the box with Symfony reverse proxy, but it's of course possible ot use Varnish to achieve the same.

User hash generation with Varnish 4

New anonymous X-User-Hash

The anonymous X-User-Hash is generated based on the anonymous user, group and role. The 38015b703d82206ebc01d17a39c727e5 hash that is provided in the code above will work only when these three variables are left unchanged. Once you change the default permissions and settings, the X-User-Hash will change and Varnish won't be able to effectively handle cache anymore.

In that case you need to find out the new anonymous X-User-Hash and change the VCL accordingly, else Varnish will return a no-cache header.

The easiest way to find the new hash is:

1. Connect to your server (shh should be enough)

2. Add <your-domain.com> to your /etc/hosts file

3. Execute the following command:

curl -I -H "Accept: application/vnd.fos.user-context-hash" http://<your-domain.com>/_fos_user_context_hash

You should get a result like this:

4. Now, replace the existing X-User-Hash value with the new one:

5. Restart the Varnish server and everything should work fine.

Default options for FOSHttpCacheBundle defined in eZ

The following configuration is defined in eZ by default for FOSHttpCacheBundle. You may override these settings.

 

 

Credits

This feature is based on Context aware HTTP caching post by asm89.