|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2008-2011 Ingo Renner <ingo@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 00026 /** 00027 * A cache handling helper class 00028 * 00029 * @author Ingo Renner <ingo@typo3.org> 00030 * @package TYPO3 00031 * @subpackage t3lib 00032 */ 00033 class t3lib_cache { 00034 /** 00035 * @var boolean 00036 */ 00037 protected static $isCachingFrameworkInitialized = FALSE; 00038 00039 /** 00040 * Initializes the caching framework by loading the cache manager and factory 00041 * into the global context. 00042 * 00043 * @return void 00044 */ 00045 public static function initializeCachingFramework() { 00046 if (!self::isCachingFrameworkInitialized()) { 00047 $GLOBALS['typo3CacheManager'] = t3lib_div::makeInstance('t3lib_cache_Manager'); 00048 $GLOBALS['typo3CacheFactory'] = t3lib_div::makeInstance('t3lib_cache_Factory'); 00049 $GLOBALS['typo3CacheFactory']->setCacheManager($GLOBALS['typo3CacheManager']); 00050 self::$isCachingFrameworkInitialized = TRUE; 00051 } 00052 } 00053 00054 /** 00055 * initializes the cache_pages cache 00056 * 00057 * @return void 00058 * @author Ingo Renner <ingo@typo3.org> 00059 */ 00060 public static function initPageCache() { 00061 try { 00062 $GLOBALS['typo3CacheFactory']->create( 00063 'cache_pages', 00064 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pages']['frontend'], 00065 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pages']['backend'], 00066 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pages']['options'] 00067 ); 00068 } catch (t3lib_cache_exception_DuplicateIdentifier $e) { 00069 // do nothing, a cache_pages cache already exists 00070 } 00071 } 00072 00073 /** 00074 * initializes the cache_pagesection cache 00075 * 00076 * @return void 00077 * @author Ingo Renner <ingo@typo3.org> 00078 */ 00079 public static function initPageSectionCache() { 00080 try { 00081 $GLOBALS['typo3CacheFactory']->create( 00082 'cache_pagesection', 00083 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pagesection']['frontend'], 00084 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pagesection']['backend'], 00085 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pagesection']['options'] 00086 ); 00087 } catch (t3lib_cache_exception_DuplicateIdentifier $e) { 00088 // do nothing, a cache_pagesection cache already exists 00089 } 00090 } 00091 00092 /** 00093 * initializes the cache_hash cache 00094 * 00095 * @return void 00096 * @author Ingo Renner <ingo@typo3.org> 00097 */ 00098 public static function initContentHashCache() { 00099 try { 00100 $GLOBALS['typo3CacheFactory']->create( 00101 'cache_hash', 00102 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_hash']['frontend'], 00103 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_hash']['backend'], 00104 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_hash']['options'] 00105 ); 00106 } catch (t3lib_cache_exception_DuplicateIdentifier $e) { 00107 // do nothing, a cache_hash cache already exists 00108 } 00109 } 00110 00111 /** 00112 * Determines whether the caching framework is initialized. 00113 * The caching framework could be disabled for the core but used by an extension. 00114 * 00115 * @return boolean 00116 */ 00117 public function isCachingFrameworkInitialized() { 00118 if (!self::$isCachingFrameworkInitialized 00119 && isset($GLOBALS['typo3CacheManager']) && $GLOBALS['typo3CacheManager'] instanceof t3lib_cache_Manager 00120 && isset($GLOBALS['typo3CacheFactory']) && $GLOBALS['typo3CacheFactory'] instanceof t3lib_cache_Factory 00121 ) { 00122 self::$isCachingFrameworkInitialized = TRUE; 00123 } 00124 00125 return self::$isCachingFrameworkInitialized; 00126 } 00127 00128 /** 00129 * Enables the caching framework for the core caches like cache_pages, cache_pagesection and cache_hash. 00130 * This method can be called by extensions in their ext_localconf.php. Calling it later would not work, 00131 * since rendering is already started using the defined caches. 00132 * 00133 * @return void 00134 */ 00135 public function enableCachingFramework() { 00136 if (!defined('TYPO3_UseCachingFramework')) { 00137 $GLOBALS['TYPO3_CONF_VARS']['SYS']['useCachingFramework'] = 1; 00138 } elseif (!TYPO3_UseCachingFramework) { 00139 throw new RuntimeException( 00140 'The caching framework was already defined to be disabled and cannot be changed. ' . 00141 'Please put your call to t3lib_cache::enableCachingFramework() into ext_localconf.php.', 00142 1253273131 00143 ); 00144 } 00145 } 00146 } 00147 00148 00149 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_cache.php'])) { 00150 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_cache.php']); 00151 } 00152 00153 ?>
1.8.0