public static \Joomla\CMS\Cache\CacheStorage
getInstance
(mixed $handler = null, mixed $options = array())
/**
* Returns a cache storage handler object.
*
* @param string $handler The cache storage handler to instantiate
* @param array $options Array of handler options
*
* @return CacheStorage
*
* @since 1.7.0
* @throws \UnexpectedValueException
* @throws UnsupportedCacheException
*/
public static function getInstance($handler = null, $options = array())
{
static $now = null;
if (!isset($handler)) {
$handler = Factory::getApplication()->get('cache_handler');
if (empty($handler)) {
throw new \UnexpectedValueException('Cache Storage Handler not set.');
}
}
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));
/** @var CacheStorage $class */
$class = __NAMESPACE__ . '\\Storage\\' . ucfirst($handler) . 'Storage';
if (!class_exists($class)) {
$class = 'JCacheStorage' . ucfirst($handler);
}
if (!class_exists($class)) {
// Search for the class file in the JCacheStorage include paths.
$path = Path::find(self::addIncludePath(), strtolower($handler) . '.php');
if ($path === false) {
throw new UnsupportedCacheException(sprintf('Unable to load Cache Storage: %s', $handler));
}
\JLoader::register($class, $path);
// The class should now be loaded
if (!class_exists($class)) {
throw new UnsupportedCacheException(sprintf('Unable to load Cache Storage: %s', $handler));
}
}
// Validate the cache storage is supported on this platform
if (!$class::isSupported()) {
throw new UnsupportedCacheException(sprintf('The %s Cache Storage is not supported on this platform.', $handler));
}
return new $class($options);
}