/** * Get cache handler. * * Note this cache will ignore the cache setting in Joomla configuration. * * @param string $handler The cache handler name. * @param string $storage The storage name. * * @return \JCache|\JCacheController|\JCacheControllerClosure */ public static function getCache($handler = 'closure', $storage = 'runtime') { static $included = false; if (!$included) { \JCacheStorage::addIncludePath(__DIR__); \JCacheController::addIncludePath(__DIR__); $included = true; } $handler = $handler ?: 'closure'; $cache = \JFactory::getCache('windwalker', $handler, $storage); $cache->setCaching(true); return $cache; }
/** * Returns a cache storage handler object, only creating it * if it doesn't already exist. * * @param string $handler The cache storage handler to instantiate * @param array $options Array of handler options * * @return JCacheStorageHandler A JCacheStorageHandler object * * @since 11.1 */ public static function getInstance($handler = null, $options = array()) { static $now = null; JCacheStorage::addIncludePath(JPATH_PLATFORM . '/joomla/cache/storage'); if (!isset($handler)) { $conf = JFactory::getConfig(); $handler = $conf->get('cache_handler'); if (empty($handler)) { return JError::raiseWarning(500, JText::_('JLIB_CACHE_ERROR_CACHE_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)); $class = 'JCacheStorage' . ucfirst($handler); if (!class_exists($class)) { // Search for the class file in the JCacheStorage include paths. jimport('joomla.filesystem.path'); if ($path = JPath::find(JCacheStorage::addIncludePath(), strtolower($handler) . '.php')) { include_once $path; } else { return JError::raiseWarning(500, JText::sprintf('JLIB_CACHE_ERROR_CACHE_STORAGE_LOAD', $handler)); } } return new $class($options); }