KnpLabs/KnpBundles — pull request #225 by barelon (2012-08-31 21:36:14+00:00)
Title: Bug/cache

Knpbundles uses ESI for the top user bar, so that it is cached differently from the rest of the page. Unfortunately this currently does not work and many times, after logging in, the top menu is rendered as when you are not logged in and viceversa and you need to reload the page to see the change of status. The problem arises because the main bundle listing controller sets max-age and according to the symfony docs (http://symfony.com/doc/master/book/http_cache.html#using-esi-in-symfony2 ):

*"Once you start using ESI, remember to always use the s-maxage directive instead of max-age. As the browser only ever receives the aggregated resource, it is not aware of the sub-components, and so it will obey the max-age directive and cache the entire page. And you don't want that."*

So, currently the browser caches the whole page and that is why you many times don´t see the login changes. What I did is change setMaxAge to setSharedMaxAge as the docs recommend. I also set a max-age of 0 and set the must-revalidate header in the user bar controller so that this user section is always revalidated with the server