Ejemplo n.º 1
0
 /**
  * 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);
     }
 }