Tuesday, May 31, 2011

Caching

I've raised a similar question before but got no responses, so I'll
try something more specific.

I have an application that is pretty dynamic. With no caching turned
on there is a lag of around 2 seconds before anything happens, and
then it all zips in really quickly. If I blanket enable view caching
(enabling cache in core.php, adding the Cache helper to app_controller
and setting cacheAction to +1hour) the lag disappears, response is
fantastic but the results are (understandably) terrible as nothing is
dynamic.

If I move the cache setting from app_controller into specific actions
I start to get better results. It's a pretty big app, so that's going
to take a lot of time and testing to do correctly. However, I have a
particular problem that I need to solve before I put in the effort.

I have a navigation component that reads $this->params, sets up some
variables that are passed through the controller and rendered in an
element (that also has a nested element):

function beforeRender() {
$this->set('menus', $this->Navigation->menus($this->params));

I have placed <cake:nocache></cake:nocache> blocks in the elements.

Reading the Cake on line book:
"It should be noted that once an action is cached, the controller
method for the action will not be called - otherwise what would be the
point of caching the page. Therefore, it is not possible to wrap
<cake:nocache> </cake:nocache> around variables which are set from the
controller as they will be null."

As every page contains the navigation code, it would seem that I
cannot pass the menus variable down. Subsequent rendering of the
navigation (when the contents have changed) delivers lots of
'Undefined index' errors as the variables are indeed missing. This is
especially so when a user logs in and then logs, which generates
different menu content.

Can anyone suggest a work around for this?

--
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: