463b3c9810ce70ed7bfa4da71ff2285f14458289
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Cache / Cache.php
1 <?php
2 namespace TYPO3\CMS\Core\Cache;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2008-2013 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * A cache handling helper class
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 */
31 class Cache {
32
33 /**
34 * @var boolean
35 */
36 static protected $isCachingFrameworkInitialized = FALSE;
37
38 /**
39 * Initializes the caching framework by loading the cache manager and factory
40 * into the global context.
41 *
42 * @return void
43 */
44 static public function initializeCachingFramework() {
45 if (!self::isCachingFrameworkInitialized()) {
46 // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
47 $GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Cache\CacheManager();
48 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $GLOBALS['typo3CacheManager']);
49 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
50 // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
51 $GLOBALS['typo3CacheFactory'] = new \TYPO3\CMS\Core\Cache\CacheFactory('production', $GLOBALS['typo3CacheManager']);
52 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', $GLOBALS['typo3CacheFactory']);
53 self::$isCachingFrameworkInitialized = TRUE;
54 }
55 }
56
57 /**
58 * Determines whether the caching framework is initialized.
59 * The caching framework could be disabled for the core but used by an extension.
60 *
61 * @return boolean True if caching framework is initialized
62 */
63 static public function isCachingFrameworkInitialized() {
64 if (!self::$isCachingFrameworkInitialized && isset($GLOBALS['typo3CacheManager']) && $GLOBALS['typo3CacheManager'] instanceof \TYPO3\CMS\Core\Cache\CacheManager && isset($GLOBALS['typo3CacheFactory']) && $GLOBALS['typo3CacheFactory'] instanceof \TYPO3\CMS\Core\Cache\CacheFactory) {
65 self::$isCachingFrameworkInitialized = TRUE;
66 }
67 return self::$isCachingFrameworkInitialized;
68 }
69
70 /**
71 * Helper method for install tool and extension manager to determine
72 * required table structure of all caches that depend on it
73 *
74 * This is not a public API method!
75 *
76 * @return string Required table structure of all registered caches
77 */
78 static public function getDatabaseTableDefinitions() {
79 $tableDefinitions = '';
80 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
81 $backend = $GLOBALS['typo3CacheManager']->getCache($cacheName)->getBackend();
82 if (method_exists($backend, 'getTableDefinitions')) {
83 $tableDefinitions .= LF . $backend->getTableDefinitions();
84 }
85 }
86 return $tableDefinitions;
87 }
88
89 }