[Solar-talk] Moving layout vars to outside
Rodrigo Moraes
rodrigo.moraes at gmail.com
Sat Jan 27 09:19:23 PST 2007
Hi, again. More about response object discoveries...
I started to refactor layouts because I was looking for a cache
solution for templates that would not be everywhere inside controllers
(call cache; check cache; save cache - over and over). Last week I
needed to cache view parts to improve performance, and the controllers
started to become full of pieces of code used by the cache - and they
started to become ugly and a mess.
Putting most of the view fetching out of the controller allowed to
attach a unique cache mechanism to the response object; and being
centralized in one place, it is of course easier to manage and
maintain. The controller only asks to the response object if it should
execute an expensive operation or if it is cached already:
if(!$this->_response->getBlock('sidebar', 'my_cache_id')) {
$model = Solar::factory('My_Model');
$this->items = $model->fetchAll();
}
When a cache id is passed, the response object checks if it is cached
and "registers" (in an internal array) the cached result to be later
assign to that block part, returning true to the controller. If not
cached, it returns false and after fetching the template it uses the
block info to cache it. If no cache id is passed it returns false and
the template is always fetched normally. This allows the mix of cached
and dynamic template pieces without a lot of mess in the code.
And, oh, I'm justing telling you all of this because I looked a lot
for a clean solution for cache that allowed dynamic parts and kept the
controller a bit independent from cache checkings and savings etc.
Sorry for the long post; I hope there is some interest in cache
solutions here. Any thpughts or other ideas are appreciated. :-)
rodrigo
More information about the solar-talk
mailing list