JCacheStorage/getInstance: Difference between revisions
From Joomla! Documentation
m removing red link to edit, no existant pages |
m preparing for archive only |
||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
Returns a cache storage hanlder object, only creating it if it doesn't already exist. | Returns a cache storage hanlder object, only creating it if it doesn't already exist. | ||
<! removed transcluded page call, red link never existed > | <! removed transcluded page call, red link never existed > | ||
| Line 60: | Line 58: | ||
</source> | </source> | ||
<! removed transcluded page call, red link never existed > | <! removed transcluded page call, red link never existed > | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=getInstance | category=getInstance | ||
category=JCacheStorage | category=JCacheStorage | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
Latest revision as of 01:22, 25 March 2017
Description
Returns a cache storage hanlder object, only creating it if it doesn't already exist.
<! removed transcluded page call, red link never existed >
Syntax
getInstance($handler= 'file', $options=array())
| Parameter Name | Default Value | Description |
|---|---|---|
| $handler | 'file' | $handler The cache storage handler to instantiate |
| $options | array() |
Returns
object A JCacheStorageHandler object
Defined in
libraries/joomla/cache/storage.php
Importing
jimport( 'joomla.cache.storage' );
Source Body
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);
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples