/** * Factory method which creates the specified cache along with the specified kind of backend. * After creating the cache, it will be registered at the cache manager. * * @param string $cacheIdentifier The name / identifier of the cache to create * @param string $cacheObjectName Object name of the cache frontend * @param string $backendObjectName Object name of the cache backend * @param array $backendOptions (optional) Array of backend options * @return \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface The created cache frontend * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidBackendException if the cache backend is not valid * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidCacheException if the cache frontend is not valid * @api */ public function create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions = array()) { // New operator used on purpose: This class is required early during // bootstrap before makeInstance() is propely set up $backendObjectName = '\\' . ltrim($backendObjectName, '\\'); $backend = new $backendObjectName($this->context, $backendOptions); if (!$backend instanceof \TYPO3\CMS\Core\Cache\Backend\BackendInterface) { throw new \TYPO3\CMS\Core\Cache\Exception\InvalidBackendException('"' . $backendObjectName . '" is not a valid cache backend object.', 1216304301); } if (is_callable(array($backend, 'initializeObject'))) { $backend->initializeObject(); } // New used on purpose, see comment above $cache = new $cacheObjectName($cacheIdentifier, $backend); if (!$cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) { throw new \TYPO3\CMS\Core\Cache\Exception\InvalidCacheException('"' . $cacheObjectName . '" is not a valid cache frontend object.', 1216304300); } if (is_callable(array($cache, 'initializeObject'))) { $cache->initializeObject(); } $this->cacheManager->registerCache($cache); return $cache; }
/** * Initializes the cache and determines caching method. * * @author Martin Helmich <*****@*****.**> * @version 2008-10-11 * @param string $mode The caching mode. This may either be 'auto', * 'apc','database','file' or 'none' (see above). * @param array $configuration * @throws Exception */ function init($mode = 'auto', $configuration = array()) { /* If mode is set to 'auto' or 'apc', first try to set mode * to APC (if enabled) or otherwise to database. */ if ($mode == 'auto' || $mode == 'apc') { if ($this->getAPCEnabled()) { $useMode = 'apc'; } else { $useMode = 'database'; } /* If mode is set to 'file',... */ } elseif ($mode == 'file') { $useMode = 'file'; } elseif ($mode == 'none') { $useMode = 'none'; } else { $useMode = 'database'; } /* Compose class name and instantiate */ if (isset($GLOBALS['typo3CacheManager'])) { $this->useTYPO3Cache = TRUE; if ($useMode == 'database') { $this->cacheObj =& $this->typo3CacheManager->getCache('cache_hash'); } else { if ($this->typo3CacheManager->hasCache('mm_forum')) { $this->cacheObj =& $this->typo3CacheManager->getCache('mm_forum'); } else { switch ($useMode) { case 'database': $className = 't3lib_cache_backend_DbBackend'; break; case 'apc': $className = 't3lib_cache_backend_ApcBackend'; break; case 'file': $className = 't3lib_cache_backend_FileBackend'; break; case 'none': $className = 't3lib_cache_backend_NullBackend'; break; case 'globals': $className = 't3lib_cache_backend_GlobalsBackend'; break; default: throw new Exception("Unknown caching mode: {$useMode}", 1296594227); } if (!class_exists($className) && file_exists(PATH_t3lib . 'cache/backend/class.' . strtolower($className) . '.php')) { include_once PATH_t3lib . 'cache/backend/class.' . strtolower($className) . '.php'; } elseif (!class_exists($className)) { $this->cacheObj =& $this->typo3CacheManager->getCache('cache_hash'); } if (class_exists($className)) { $cacheBackend = GeneralUtility::makeInstance($className, $configuration); $cacheObject = GeneralUtility::makeInstance('t3lib_cache_frontend_VariableFrontend', 'mm_forum', $cacheBackend); $this->typo3CacheManager->registerCache($cacheObject); $this->cacheObj =& $this->typo3CacheManager->getCache('mm_forum'); } else { throw new Exception("Cache backend does not exist: {$className}", 1296594228); } } } } else { $className = 'tx_mmforum_cache_' . $useMode; $this->cacheObj =& GeneralUtility::makeInstance($className); } }