2 /***************************************************************
5 * (c) 2008-2009 Ingo Renner <ingo@typo3.org>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * A cache handling helper class
29 * @author Ingo Renner <ingo@typo3.org>
37 protected static $isCachingFrameworkInitialized = false
;
40 * Initializes the caching framework by loading the cache manager and factory
41 * into the global context.
45 public static function initializeCachingFramework() {
46 if (!self
::isCachingFrameworkInitialized()) {
47 $GLOBALS['typo3CacheManager'] = t3lib_div
::makeInstance('t3lib_cache_Manager');
48 $GLOBALS['typo3CacheFactory'] = t3lib_div
::makeInstance('t3lib_cache_Factory');
49 $GLOBALS['typo3CacheFactory']->setCacheManager($GLOBALS['typo3CacheManager']);
50 self
::$isCachingFrameworkInitialized = true
;
55 * initializes the cache_pages cache
58 * @author Ingo Renner <ingo@typo3.org>
60 public static function initPageCache() {
62 $GLOBALS['typo3CacheFactory']->create(
64 't3lib_cache_frontend_VariableFrontend',
65 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pages']['backend'],
66 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pages']['options']
68 } catch(t3lib_cache_exception_DuplicateIdentifier
$e) {
69 // do nothing, a cache_pages cache already exists
74 * initializes the cache_pagesection cache
77 * @author Ingo Renner <ingo@typo3.org>
79 public static function initPageSectionCache() {
81 $GLOBALS['typo3CacheFactory']->create(
83 't3lib_cache_frontend_VariableFrontend',
84 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pagesection']['backend'],
85 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pagesection']['options']
87 } catch(t3lib_cache_exception_DuplicateIdentifier
$e) {
88 // do nothing, a cache_pagesection cache already exists
93 * initializes the cache_hash cache
96 * @author Ingo Renner <ingo@typo3.org>
98 public static function initContentHashCache() {
100 $GLOBALS['typo3CacheFactory']->create(
102 't3lib_cache_frontend_VariableFrontend',
103 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_hash']['backend'],
104 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_hash']['options']
106 } catch(t3lib_cache_exception_DuplicateIdentifier
$e) {
107 // do nothing, a cache_hash cache already exists
112 * Determines whether the caching framework is initialized.
113 * The caching framework could be disabled for the core but used by an extension.
117 public function isCachingFrameworkInitialized() {
118 if (!self
::$isCachingFrameworkInitialized
119 && isset($GLOBALS['typo3CacheManager']) && $GLOBALS['typo3CacheManager'] instanceof t3lib_cache_Manager
120 && isset($GLOBALS['typo3CacheFactory']) && $GLOBALS['typo3CacheFactory'] instanceof t3lib_cache_Factory
122 self
::$isCachingFrameworkInitialized = true
;
125 return self
::$isCachingFrameworkInitialized;
129 * Enables the caching framework for the core caches like cache_pages, cache_pagesection and cache_hash.
130 * This method can be called by extensions in their ext_localconf.php. Calling it later would not work,
131 * since rendering is already started using the defined caches.
135 public function enableCachingFramework() {
136 if (!defined('TYPO3_UseCachingFramework')) {
137 $GLOBALS['TYPO3_CONF_VARS']['SYS']['useCachingFramework'] = 1;
138 } elseif (!TYPO3_UseCachingFramework
) {
139 throw new RuntimeException(
140 'The caching framework was already defined to be disabled and cannot be changed. ' .
141 'Please put your call to t3lib_cache::enableCachingFramework() into ext_localconf.php.',
149 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_cache.php']) {
150 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_cache.php']);