Sunday, October 30, 2011

Cached Forms Don't Submit

I have setup the index and edit actions to be cached in my
PostsController as follows:

var $cacheAction = array(
'index' => array('callbacks' => true, 'duration' => '7 days'),
'edit' => array('callbacks' => true, 'duration' => '7 days'),
);

Everything is cached as expected, but the edit form doesn't submit.
This is expected as well, if you think about it, but is there anyway
to bypass caching when a user submits a form?

I set callbacks to true to allow AuthComponent to do its magic, so if
I could put some code in beforeFilter(), it's executed dynamically
(not cached). I have tried each of the following in beforeFilter(),
one by one, but none of them did the trick:

if(!empty($this->data)) clearCache();
if(!empty($this->data)) Configure::write('Cache.check', false);
if(!empty($this->data)) $this->cacheAction = false;

To avoid the "why would you even want to do that" argument I see in
other forums, I'll explain a little further. My edit action is fairly
intensive since it's such a long form with a lot of "stuff" in it and
caching definitely improves the performance. To avoid writing extra
code, the edit action displays the form as well as saves it.

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: