Fixed bug #14005: Moving a page with IRRE records misplaces IRRE records
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_cache.php
index a6c8218..06ae75d 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2008 Ingo Renner <ingo@typo3.org>
+*  (c) 2008-2009 Ingo Renner <ingo@typo3.org>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -22,7 +22,6 @@
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
 
-require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
 
 /**
  * A cache handling helper class
@@ -32,6 +31,25 @@ require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
  * @subpackage t3lib
  */
 class t3lib_cache {
+       /**
+        * @var boolean
+        */
+       protected static $isCachingFrameworkInitialized = false;
+
+       /**
+        * Initializes the caching framework by loading the cache manager and factory
+        * into the global context.
+        *
+        * @return      void
+        */
+       public static function initializeCachingFramework() {
+               if (!self::isCachingFrameworkInitialized()) {
+                       $GLOBALS['typo3CacheManager'] = t3lib_div::makeInstance('t3lib_cache_Manager');
+                       $GLOBALS['typo3CacheFactory'] = t3lib_div::makeInstance('t3lib_cache_Factory');
+                       $GLOBALS['typo3CacheFactory']->setCacheManager($GLOBALS['typo3CacheManager']);
+                       self::$isCachingFrameworkInitialized = true;
+               }
+       }
 
        /**
         * initializes the cache_pages cache
@@ -89,6 +107,42 @@ class t3lib_cache {
                                // do nothing, a cache_hash cache already exists
                }
        }
+
+       /**
+        * Determines whether the caching framework is initialized.
+        * The caching framework could be disabled for the core but used by an extension.
+        *
+        * @return      boolean
+        */
+       public function isCachingFrameworkInitialized() {
+               if (!self::$isCachingFrameworkInitialized
+                       && isset($GLOBALS['typo3CacheManager']) && $GLOBALS['typo3CacheManager'] instanceof t3lib_cache_Manager
+                       && isset($GLOBALS['typo3CacheFactory']) && $GLOBALS['typo3CacheFactory'] instanceof t3lib_cache_Factory
+               ) {
+                       self::$isCachingFrameworkInitialized = true;
+               }
+
+               return self::$isCachingFrameworkInitialized;
+       }
+
+       /**
+        * Enables the caching framework for the core caches like cache_pages, cache_pagesection and cache_hash.
+        * This method can be called by extensions in their ext_localconf.php. Calling it later would not work,
+        * since rendering is already started using the defined caches.
+        *
+        * @return      void
+        */
+       public function enableCachingFramework() {
+               if (!defined('TYPO3_UseCachingFramework')) {
+                       $GLOBALS['TYPO3_CONF_VARS']['SYS']['useCachingFramework'] = 1;
+               } elseif (!TYPO3_UseCachingFramework) {
+                       throw new RuntimeException(
+                               'The caching framework was already defined to be disabled and cannot be changed. ' .
+                               'Please put your call to t3lib_cache::enableCachingFramework() into ext_localconf.php.',
+                               1253273131
+                       );
+               }
+       }
 }