I cannot get this to work in 2.2. This is what I have tried:

First I just followed the book to create JSON views (
http://book.cakephp.org/2.0/en/views/json-and-xml-views.html). Works great. 
I get JSON data back.

Then I followed the CacheHelper instructions (
http://book.cakephp.org/2.0/en/core-libraries/helpers/cache.html). I 
un-commented Cache.check in core.php, added the CacheHelper in my 
Controller and defined $cacheAction. This works great for HTML Views. But, 
for JSON views nothing gets cached unfortunately.

I found this post: 
http://lars-schenk.com/cached-json-or-xml-view-with-cakephp/523 that ran 
into a similar issue (albeit in an earlier version of Cake that didn't have 
JsonView yet).

So I tried to use his method, and apply it to 2.2. I took 
Router::parseExtensions( 'json' ) out, took the RequestHandler out, created 
a json.ctp layout file.


<!--nocache--><?php
configure::write('debug',0); // surpress all debug output on json views
header('Content-type: text/x-json');?><!--nocache--><?php echo 
$this->fetch('content'); ?>
 

a feed.ctp view file

<?php echo json_encode( $data ); ?>
 

and changed my controller action to just set the layout and data

$this->layout = 'json';$this->view = 'feed';$this->set( 'data', $data );
 

This works somewhat. I get the JSON file the first time, but when I request 
that action again, the response contains

<!--nocache:001--><!--nocache:002-->
 

before the actual JSON data, so it won't work for my client app. I can see 
that chunk of text in the actual cache file as well, which I think is the 
problem.

So I am not quite sure how to proceed.

Am I just missing something painfully obvious?

Any help would be greatly appreciated.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to