Login / Status
developer.Resource
Home . Development . Articles . Using Cache-Control Headers in TYPO3
Sponsors
hosted by punkt.deTYPO3 and Open Source Magazine
<<  The theory of client-side caching  Enabling cache-control headers in TYPO3 Conclusion >> 

Enabling cache-control headers in TYPO3

There is a new option called sendCacheHeaders in the CONFIG top level object of TypoScript. If it is set, TYPO3 will output cache-control headers to the client. This conditionally allows client browsers and/or reverse proxies to take load off of TYPO3 websites.

The conditions for allowing client and/or proxy caching are the following: 

  • The page was cached by TYPO3 

  • No *_INT or *_EXT objects were on the page (e.g. USER_INT) 

  • No frontend user is logged in 

  • No backend user is logged in 

If these conditions are met, headers are sent that allow caching of the page. In case caching is not allowed after evaluating the above conditions, headers are sent to prohibit client caching. Details about what headers are sent can be found in TSref. 

To avoid potential problems TYPO3 of course honors client requests for cache revalidation and regenerates a page internally if asked to do so. 

More on caching and FE user logins

Above it has been said that cache-control headers are not sent when a user is logged in. This is needed because in TYPO3 the same URL can show different content depending on whether a user is logged in or not. But if the same URL was visited without a login prior to the login (therefore allowing caching) the user will still see the page from cache when logged in - and so thinks he is not logged in anyway!

One way to solve this, is to have different URLs when users are logged in (this could be achieved with the realurl extension). Another way is to set the sendCacheHeaders_onlyWhenLoginDeniedInBranch option in the CONFIG top level object of TypoScript. Then cache-control headers are only sent when user logins are disabled for a page or a branch of pages (possible in the „Advanced“ page type).

Since many sites only need the login in a certain branch of the page tree, disabling it in all other branches makes it much easier to use cache-control headers in combination with logins: cache-control headers will simply be sent when logins are not allowed and never be sent when logins are allowed!

Practical Considerations

Notice that enabling caching means you have to consider how log files are written: When a page is cached on the client, it will not be requested from the web server, thus no logging will happen. Often the client will ask the proxy and using Apache as proxy makes it easy to get the same logging as before. So there are ways to circumvent these problems but they are outside the domain of TYPO3 in any case.