views:

318

answers:

3

Essentially I have a PHP page that calls out some other HTML to be rendered through an object's method. It looks like this:

MY PHP PAGE:

// some content...

<?php
    $GLOBALS["topOfThePage"] = true;
    $this->renderSomeHTML();
?>

// some content...

<?php
    $GLOBALS["topOfThePage"] = false;
    $this->renderSomeHTML();
?>

The first method call is cached, but I need renderSomeHTML() to display slightly different based upon its location in the page. I tried passing through to $GLOBALS, but the value doesn't change, so I'm assuming it is getting cached.

Is this not possible without passing an argument through the method or by not caching it? Any help is appreciated. This is not my application -- it is Magento.

Edit:

This is Magento, and it looks to be using memcached. I tried to pass an argument through renderSomeHTML(), but when I use func_get_args() on the PHP include to be rendered, what comes out is not what I put into it.

Edit:

Further down the line I was able to "invalidate" the cache by calling a different method that pulled the same content and passing in an argument that turned off caching. Thanks everyone for your help.

+1  A: 

Chaching is handled differently by different frameworks, so you'd have to help us out with some more information. But I also wonder if you could pass that as a parameter instead of using $GLOBALS.

$this->renderSomeHTML(true);
DGM
+3  A: 

Obviously, you cannot. The whole point of caching is that the 'thing' you cache is not going to change. So you either:

  • provide a parameter
  • aviod caching
  • invalidate the cache when you set a different parameter

Or, you rewrite the cache mechanism yourself - to support some dynamic binding.

Milan Babuškov
A: 

Your question seems unclear, but caching pretty much means 'stored so we don't have to calculate it again'. If you want the content to differ, you need to cache more results and pick the correct cached object one to send back.

Need more info to give a better answer. What is caching the document, Smarty? And what do you mean by "its location in the page"? What is 'it'?

RobbieGee