[TASK] Use simple file backend for core php cache
[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 // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
48 $GLOBALS['typo3CacheManager'] = new t3lib_cache_Manager();
49 t3lib_div::setSingletonInstance('t3lib_cache_Manager', $GLOBALS['typo3CacheManager']);
50 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
51 // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
52 $GLOBALS['typo3CacheFactory'] = new t3lib_cache_Factory('production', $GLOBALS['typo3CacheManager']);
53 t3lib_div::setSingletonInstance('t3lib_cache_Factory', $GLOBALS['typo3CacheFactory']);
54 self::$isCachingFrameworkInitialized = TRUE;
55 }
56 }
57
58 /**
59 * Determines whether the caching framework is initialized.
60 * The caching framework could be disabled for the core but used by an extension.
61 *
62 * @return boolean True if caching framework is initialized
63 */
64 public static function isCachingFrameworkInitialized() {
65 if (!self::$isCachingFrameworkInitialized
66 && isset($GLOBALS['typo3CacheManager']) && $GLOBALS['typo3CacheManager'] instanceof t3lib_cache_Manager
67 && isset($GLOBALS['typo3CacheFactory']) && $GLOBALS['typo3CacheFactory'] instanceof t3lib_cache_Factory
68 ) {
69 self::$isCachingFrameworkInitialized = TRUE;
70 }
71
72 return self::$isCachingFrameworkInitialized;
73 }
74
75 /**
76 * Helper method for install tool and extension manager to determine
77 * required table structure of all caches that depend on it
78 *
79 * This is not a public API method!
80 *
81 * @return string Required table structure of all registered caches
82 */
83 public static function getDatabaseTableDefinitions() {
84 $tableDefinitions = '';
85 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
86 $backend = $GLOBALS['typo3CacheManager']->getCache($cacheName)->getBackend();
87 if (method_exists($backend, 'getTableDefinitions')) {
88 $tableDefinitions .= LF . $backend->getTableDefinitions();
89 }
90 }
91 return $tableDefinitions;
92 }
93 }
94 ?>