API16

API16:JCache/getInstance

From Joomla! Documentation

Revision as of 22:38, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Returns a reference to a cache adapter object, always creating it <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JCache/getInstanc...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Returns a reference to a cache adapter object, always creating it

[Edit Descripton]

Template:Description:JCache/getInstance

Syntax

getInstance($type= 'output', $options=array())
Parameter Name Default Value Description
$type 'output' $type The cache object type to instantiate
$options array()

Returns

object A object

Defined in

libraries/joomla/cache/cache.php

Importing

jimport( 'joomla.cache.cache' );

Source Body

function getInstance($type = 'output', $options = array())
{
        $type = strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $type));

        $class = 'JCache'.ucfirst($type);

        if (!class_exists($class))
        {
                $path = dirname(__FILE__).DS.'handler'.DS.$type.'.php';

                if (file_exists($path)) {
                        require_once $path;
                } else {
                        JError::raiseError(500, 'Unable to load Cache Handler: '.$type);
                }
        }

        return new $class($options);
}

[Edit See Also] Template:SeeAlso:JCache/getInstance

Examples

<CodeExamplesForm />