Wednesday, January 25, 2012

Caching (in 1.3) -> $this->viewVars and many content -> file size explodes

Hey everyone,

the cached view in /tmp/cache/views, e.g. lets assume an
*articles_index.php* always contain the $controller->viewVars = $this-
>viewVars = (…); this simply cointains an array with all the data the
action uses (so the data which is submitted with $this->set).
Sometimes this data is base64 encoded + serialized, sometimes the
arrays are included directly (?!).

This leads to problem for files with much content: e.g. my
articles_index shows the latest 200 articles, so 200 arrays with
title, img, short descprition, date, author and so on for each
article. In the arrays, as often, there is much more data (the whole
article text, recursive connections to other models as comments for
the article which I count, and so on…) but in html I just display a
part of this data.

The data of all 200 articles is well placed in html, normal file size
just for this would be about 100 KB.
But now viewVars again cointains all the data of all 200 articles +
recursive models (base64 encoded or not) which is total unnecessary
but leads to a file size of about 8000 KB!
Also with not that much data (no recursive models or if I prepare the
data exactly in the controller) that file size would be about x2 / x3
with all this useless data in viewVars.

So all over caching leads to enormous traffic for me, without caching
my site is much faster than with!


I looked at __writeFile() in cake/libs/view/helpers/cache.php where
the "magic" occurs due to
"$controller->viewVars = $this->viewVars =
unserialize(base64_decode(\'' . base64_encode(serialize($this-
>viewVars)) . '\'));"

If I delete this line, of course I get problems with my <cake:nocache>
parts... I simply do not unterstand why viewVars has to contain all
the submitted data?

Appreciate any help!

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