On Fri, Apr 15, 2011 at 2:47 PM, cricket <[email protected]> wrote:
> > But yes, this is how I'm passing variables to
> > the view. Except in some of the non-cached code where I'm using
> > requestAction() to get data I need.
>
> But requestAction() is a horrible performance hog so hopefully you'll
> get all of this sorted out enough where you no longer (think you) need
> it.
>
I'm only planning to use this if I intend to actually implement view
caching. I could probably get away with storing the information retrieved by
requestAction() in the user session, which is probably how I should consider
utilizing it. Currently I'm only caching some data from the controller using
the Cache component, which helps. But I see a significant performance
increase if the view is cached as well.
> >>
> >> It's more to do with how the loop is being parsed. Put the nocache
> >> tags outside of the loop.
> >
> > I'd like to place the nocache tags around the whole loop, but this is
> where
> > my simplified example breaks down. The loop contains both cacheable and
> > non-cacheable content. I guess a good analogy to my page would be a
> product
> > list where next to each product is an icon indicating whether or not
> you've
> > placed it in your cart. So my loop actually looks closer to this (again,
> > somewhat simplified):
> >
> > <?php
> > echo '<table>';
> > foreach ($products as $product) {
> > echo '<tr><td>', $product['Product']['name'] , '</td><td>';
> > echo (in_array($product['Product']['id'], $user_cart_items) ? 'Yes' :
> > 'No');
> > echo '</td></tr>';
> > }
> > echo '</table>';
> > ?>
> >
> > So what I want to do is place the nocache tags around the Yes/No echo
> inside
> > the foreach loop. As I mentioned in an earlier email I was able to work
> > around my particular issue by using page elements. I'm also working
> around
> > one of the limitations in view caching by echoing out some PHP code so
> that
> > I can pass the current product id to my page component. So a functional
> > caching example based using the code from above would look like this:
> >
> > <?php
> > echo '<table>';
> > foreach ($products as $product) {
> > echo '<tr><td>', $product['Product']['name'] , '</td><td>';
> > $product_id = $product['Product']['id'];
> > echo "<?php $product_id = $product_id; ?>"; ?><cake:nocache><?php
> > echo $this->element('cart-control', array('product_id' => $item_id,
> > 'user_cart_items' => $user_cart_items)); ?></cake:nocache><?php
> > echo '</td></tr>';
> > }
> > echo '</table>';
>
> What the heck is this?!
> echo "<?php $product_id = $product_id; ?>"; ?>
>
> I think you should maybe consider not caching this view. That might be
> simplest.
>
As I said, this works around the limitation of not having access to
controller-set variables when the view is cached. It's actually quite like
using <nocache> ... just a bit of a hack around how cake actually does
things. Maybe a bit ugly, but what it does is not much different from what
<nocache> does. Kind of an extension of the caching mechanism. Adding this
little bit of hackery and enabling view caching can save quite a bit of
processing time.
Perhaps the "cake" way of doing this (and it just hit me) would be to use
the Cache controller/helper to store/retrieve the necessary data. I like my
way, even if it is ugly. It creates in the cached view everything that is
needed to render the page.
But yes, right now caching data and not caching the view is certainly the
simplest solution.
> > $user_cart_items is instantiated at the top of the page in a nocache
> block.
> > Ugly and confusing, yes? But it works. ;)
> >
> > Since I do have some code that works with the loop, the discussion is
> mostly
> > academic as far as that problem is concerned.
>
> If it's academic, I'm afraid I'd have to give you a D. Your
> interpretation of how view caching *should* work is not realistic.
>
I don't think that's a fair assessment. Maybe I get a D in my understanding
of the mechanics of how cake does caching. But I think my expectations of
view caching are entirely realistic. In fact, I have been able to achieve
what I expected of cake in regards to what's put in the cached file. I just
had to go about it in a less direct way (via page elements rather than code
actually on the page).
And the fact that I know enough to be able to hack around the
limitations/problems should give me some credit. So maybe a C+ ;)
There's likely a better way to go about this, but I'm a one-man shop so I
don't have days/weeks to experiment while other work piles up. This is the
only reason its academic.
--
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