[BUGFIX] Prevent compression of scripts that use ajax.php
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_cache.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2011 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 * A cache handling helper class
27 *
28 * @author Ingo Renner <ingo@typo3.org>
29 * @package TYPO3
30 * @subpackage t3lib
31 */
32 class t3lib_cache {
33
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['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
49 $GLOBALS['typo3CacheFactory'] = t3lib_div::makeInstance('t3lib_cache_Factory', 'production', $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 * @deprecated since TYPO3 4.6, will be removed in 4.8 - cacheManager->getCache() now initializes caches automatically
60 */
61 public static function initPageCache() {
62 t3lib_div::logDeprecatedFunction();
63 }
64
65 /**
66 * initializes the cache_pagesection cache
67 *
68 * @return void
69 * @author Ingo Renner <ingo@typo3.org>
70 * @deprecated since TYPO3 4.6, will be removed in 4.8 - cacheManager->getCache() now initializes caches automatically
71 */
72 public static function initPageSectionCache() {
73 t3lib_div::logDeprecatedFunction();
74 }
75
76 /**
77 * initializes the cache_hash cache
78 *
79 * @return void
80 * @author Ingo Renner <ingo@typo3.org>
81 * @deprecated since TYPO3 4.6, will be removed in 4.8 - cacheManager->getCache() now initializes caches automatically
82 */
83 public static function initContentHashCache() {
84 t3lib_div::logDeprecatedFunction();
85 }
86
87 /**
88 * Determines whether the caching framework is initialized.
89 * The caching framework could be disabled for the core but used by an extension.
90 *
91 * @return boolean True if caching framework is initialized
92 */
93 public static function isCachingFrameworkInitialized() {
94 if (!self::$isCachingFrameworkInitialized
95 && isset($GLOBALS['typo3CacheManager']) && $GLOBALS['typo3CacheManager'] instanceof t3lib_cache_Manager
96 && isset($GLOBALS['typo3CacheFactory']) && $GLOBALS['typo3CacheFactory'] instanceof t3lib_cache_Factory
97 ) {
98 self::$isCachingFrameworkInitialized = TRUE;
99 }
100
101 return self::$isCachingFrameworkInitialized;
102 }
103
104 /**
105 * Enables the caching framework for the core caches like cache_pages, cache_pagesection and cache_hash.
106 * This method can be called by extensions in their ext_localconf.php. Calling it later would not work,
107 * since rendering is already started using the defined caches.
108 *
109 * @deprecated since 4.6, will be removed in 4.8: The caching framework is enabled by default
110 * @return void
111 */
112 public static function enableCachingFramework() {
113 t3lib_div::logDeprecatedFunction();
114 }
115
116 /**
117 * Helper method for install tool and extension manager to determine
118 * required table structure of all caches that depend on it
119 *
120 * This is not a public API method!
121 *
122 * @return string Required table structure of all registered caches
123 */
124 public static function getDatabaseTableDefinitions() {
125 $tableDefinitions = '';
126 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
127 $backend = $GLOBALS['typo3CacheManager']->getCache($cacheName)->getBackend();
128 if (method_exists($backend, 'getTableDefinitions')) {
129 $tableDefinitions .= LF . $backend->getTableDefinitions();
130 }
131 }
132 return $tableDefinitions;
133 }
134 }
135 ?>