ZF-2329: Zend_Cache should remember HTTP headers (Content-Type) when using Zend_Cache_Frontend_Page


Example: An XML document is output with the Content-Type header set to text/xml. Zend_Cache_Frontend_Page is used and when retrieving a cached copy, the Content-Type header is incorrectly set to text/html.

See for an example. The cache time is about 15 seconds. Initiall you will see the document with the correct content-type (and correctly formatted in Firefox), refreshing will give you the cached copy (wrong content-type and not formatted in Firefox).


Zend_Cache doesn't send Content-Type header.

Something like this should work, no ?


require 'Zend/Cache.php')
[...] we make $cache object



require_once 'Model.php'

[...] your work to make the XML file

It's a possible solution but that wouldn't work in my case or most common cases when using Zend_Controller.

In my case the module/controller/action route will determine the Content-Type header which will be set on the Response object. Since Zend_Cache is setup in the bootstrap, it does not go through the entire route sequence to determine what the Content-Type should be.

As it stands your solution would work for a lot of cases when using Zend_Cache/Zend_Cache_Frontend_Page in a simple application. However, when using Zend_Cache/Zend_Cache_Frontend_Page with Zend_Controller you are essentially limited to produce text/html responses.

I just commited a change for this into the SVN trunk

please try it (you will have to set the backend option content_type_memorization = true) and reopen this task if problem


The new Zend_Cache_Frontend_Page class definately works in my case. The Content-Type header is correctly remembered and sent along with the cached output.

The content_type_memorization is a frontend option, not a backend one.

Thanks for this fix!

Problem is not limited to Content-type header; other important headers (Expires, for example) are also lost. Is there any good reason not to remember and re-use all response headers for cached pages? The patch is even simpler than the patch to add content_type_memorization. Just save the entire headers_list() array in the cache and spit them all back.

Can I close this bug? Have all issues been resolved? It's not entirely clear from the comments.

fine by me

Yes Wil, you can close it