Difference between revisions of "Core/getFromCache"

From PunchCMS
Jump to: navigation, search
(New page: __NOTOC__ ==== PCMS_Client->getFromCache(method, elementId, [arguments]) ==== === Overview === Get the output of a method from the cache. If the cache is disabled or the content has not be...)
 
(Arguments)
Line 4: Line 4:
 
Get the output of a method from the cache. If the cache is disabled or the content has not been cached yet this method will call the requested method and return/cache the output.
 
Get the output of a method from the cache. If the cache is disabled or the content has not been cached yet this method will call the requested method and return/cache the output.
 
=== Arguments ===
 
=== Arguments ===
'''method''' [string/array] <br>  
+
'''method''' [mixed] <br>  
 
The method from which the output should be cached. If the method is a static method of a class the argument should be formated as an array like this  
 
The method from which the output should be cached. If the method is a static method of a class the argument should be formated as an array like this  
 
<source lang="php">
 
<source lang="php">
Line 15: Line 15:
 
'''arguments''' [mixed, ''optional'']<br>  
 
'''arguments''' [mixed, ''optional'']<br>  
 
Optional arguments that need to be passed to the called method. More than one argument should be placed in an array.
 
Optional arguments that need to be passed to the called method. More than one argument should be placed in an array.
 +
 
=== Returns ===
 
=== Returns ===
 
The output of the called method. Either cached or fresh.
 
The output of the called method. Either cached or fresh.

Revision as of 22:39, 25 December 2008

PCMS_Client->getFromCache(method, elementId, [arguments])

Overview

Get the output of a method from the cache. If the cache is disabled or the content has not been cached yet this method will call the requested method and return/cache the output.

Arguments

method [mixed]
The method from which the output should be cached. If the method is a static method of a class the argument should be formated as an array like this

array("CLASS", "METHOD");

elementId [integer]
Id of the element this call should be tied to. If this element gets updated in the CMS the cache file will be removed to reflect the change.

arguments [mixed, optional]
Optional arguments that need to be passed to the called method. More than one argument should be placed in an array.

Returns

The output of the called method. Either cached or fresh.

Example

$objCms = PCMS_Client::getInstance();
 
// Cache the output of a parse method.
$objElement = $objCms->getElementById(1234);
$strOutput = $objCms->getFromCache("parseHeader", $objElement->getId(), 
              $objElement);
 
// Cache the output of an auxiliary static method of the class "Tools".
$arrMethod = array("Tools", "parseTitle");
$arrArguments = array("My", "title");
$strOutput = $objCms->getFromCache($arrMethod, 1234, $arrArguments);