< API15:JCacheCallback

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


Executes a cacheable callback if not found in cache else returns cached output and result

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >


get($callback, $args, $id=false)
Parameter Name Default Value Description
$callback Callback or string shorthand for a callback
$args Callback arguments
$id false


mixed Result of the callback

Defined in



jimport( 'joomla.cache.handler.callback' );

Source Body

function get( $callback, $args, $id=false )
        // Normalize callback
        if (is_array( $callback )) {
                // We have a standard php callback array -- do nothing
        } elseif (strstr( $callback, '::' )) {
                // This is shorthand for a static method callback classname::methodname
                list( $class, $method ) = explode( '::', $callback );
                $callback = array( trim($class), trim($method) );
        } elseif (strstr( $callback, '->' )) {
                 * This is a really not so smart way of doing this... we provide this for backward compatability but this
                 * WILL!!! disappear in a future version.  If you are using this syntax change your code to use the standard
                 * PHP callback array syntax: <>
                 * We have to use some silly global notation to pull it off and this is very unreliable
                list( $object_123456789, $method ) = explode('->', $callback);
                global $$object_123456789;
                $callback = array( $$object_123456789, $method );
        } else {
                // We have just a standard function -- do nothing
        if (!$id) {
                // Generate an ID
                $id = $this->_makeId($callback, $args);
        // Get the storage handler and get callback cache data by id and group
        $data = parent::get($id);
        if ($data !== false) {
                $cached = unserialize( $data );
                $output = $cached['output'];
                $result = $cached['result'];
        } else {
                ob_implicit_flush( false );
                $result = call_user_func_array($callback, $args);
                $output = ob_get_contents();
                $cached = array();
                $cached['output'] = $output;
                $cached['result'] = $result;
                // Store the cache data
                $this->store(serialize($cached), $id);
        echo $output;
        return $result;

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >


Code Examples