Hi,

I'm working on a site using CakePHP that has various feeds in JSON and
XML. I tried caching some of those feeds today using controller-level
view caching and ran into an annoying problem - cached views don't
seem to retain the mime type of the document. That is, in most cases,
a cached view (not elements) will be served up as text/html by
CakePHP, not the type of the original document.

To recreate this, simply try offering a XML or JSON based view in a
controller, cache it, then load it twice. (using parseExtensions()
might also help) The first request works correctly (uncached request),
but the second request will come back as text/html (except for an edge
case around XML).

The problem seems to be at line 508 of cake/libs/view/view.php. (I'm
using 1.2.0.7962)  This is where the view class outputs a cached view
file, if valid.  The only check here for alternative document mime-
types is this confusing check for a layout named 'xml':

   if ($this->layout === 'xml') {
     header('Content-type: text/xml');
   }

The cache file doesn't have any properties that retain the extension
or type that would have been used by RequestHandler (or other code) to
find the right content type. However, $this->here does capture the
extension implicitly.

It seems the proper thing for the caching mechanism to do is to store
the content type as a variable in the view cache file (eg, $this->ext
or $this->content_type) so that the proper header can be recreated
with the cache request.  However, I don't know much about the CakePHP
internals so I'll defer primarily to explaining the situation in hopes
of filing a good bug and rallying a fix.  This seems like a major
oversight in the caching system as feeds (ajax, json, xml) are
becoming an increasingly critical part of any modern web application.

Has anyone noticed this before? Known workaround (without modifying
cake lib code)? Is a bug already filed on this that I couldn't find?
Anything else I'm missing here?

Thanks,
skylar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to