API16

JCacheStorage/getInstance

From Joomla! Documentation

< API16:JCacheStorage
Revision as of 17:38, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Returns a cache storage hanlder object, only creating it if it doesn't already exist. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Descripti...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API16" 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.

Description[edit]

Returns a cache storage hanlder object, only creating it if it doesn't already exist.

[Edit Descripton]

Template:Description:JCacheStorage/getInstance

Syntax[edit]

getInstance($handler= 'file', $options=array())
Parameter Name Default Value Description
$handler 'file' $handler The cache storage handler to instantiate
$options array()

Returns[edit]

object A JCacheStorageHandler object

Defined in[edit]

libraries/joomla/cache/storage.php

Importing[edit]

jimport( 'joomla.cache.storage' );

Source Body[edit]

function getInstance($handler = 'file', $options = array())
{
        static $now = null;
        if (is_null($now)) {
                $now = time();
        }
        $options['now'] = $now;
        //We can't cache this since options may change...
        $handler = strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $handler));
        $class = 'JCacheStorage'.ucfirst($handler);
        if (!class_exists($class))
        {
                $path = dirname(__FILE__).DS.'storage'.DS.$handler.'.php';
                if (file_exists($path)) {
                        require_once $path;
                } else {
                        return JError::raiseWarning(500, 'Unable to load Cache Storage: '.$handler);
                }
        }

        return new $class($options);
}

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

Examples[edit]

<CodeExamplesForm />