Fixed bug #12295: Cleaning config_default, exclude values from being listed in instal...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_cache.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2009 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
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.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
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.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * A cache handling helper class
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage t3lib
32 */
33 class t3lib_cache {
34 /**
35 * @var boolean
36 */
37 protected static $isCachingFrameworkInitialized = false;
38
39 /**
40 * Initializes the caching framework by loading the cache manager and factory
41 * into the global context.
42 *
43 * @return void
44 */
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;
51 }
52 }
53
54 /**
55 * initializes the cache_pages cache
56 *
57 * @return void
58 * @author Ingo Renner <ingo@typo3.org>
59 */
60 public static function initPageCache() {
61 try {
62 $GLOBALS['typo3CacheFactory']->create(
63 'cache_pages',
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']
67 );
68 } catch(t3lib_cache_exception_DuplicateIdentifier $e) {
69 // do nothing, a cache_pages cache already exists
70 }
71 }
72
73 /**
74 * initializes the cache_pagesection cache
75 *
76 * @return void
77 * @author Ingo Renner <ingo@typo3.org>
78 */
79 public static function initPageSectionCache() {
80 try {
81 $GLOBALS['typo3CacheFactory']->create(
82 'cache_pagesection',
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']
86 );
87 } catch(t3lib_cache_exception_DuplicateIdentifier $e) {
88 // do nothing, a cache_pagesection cache already exists
89 }
90 }
91
92 /**
93 * initializes the cache_hash cache
94 *
95 * @return void
96 * @author Ingo Renner <ingo@typo3.org>
97 */
98 public static function initContentHashCache() {
99 try {
100 $GLOBALS['typo3CacheFactory']->create(
101 'cache_hash',
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']
105 );
106 } catch(t3lib_cache_exception_DuplicateIdentifier $e) {
107 // do nothing, a cache_hash cache already exists
108 }
109 }
110
111 /**
112 * Determines whether the caching framework is initialized.
113 * The caching framework could be disabled for the core but used by an extension.
114 *
115 * @return boolean
116 */
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
121 ) {
122 self::$isCachingFrameworkInitialized = true;
123 }
124
125 return self::$isCachingFrameworkInitialized;
126 }
127
128 /**
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.
132 *
133 * @return void
134 */
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.',
142 1253273131
143 );
144 }
145 }
146 }
147
148
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']);
151 }
152
153 ?>