[TASK] Streamline the use of the query cache
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 6 Aug 2011 20:09:27 +0000 (22:09 +0200)
committerXavier Perseguers <xavier@typo3.org>
Sun, 7 Aug 2011 18:27:04 +0000 (20:27 +0200)
The caching framework has been streamlined.
Registering caches for extensions and fetching the cache is much easier now.
Refactor the query cache handling in DBAL to reflect this change.

Resolves: #28805

Change-Id: I2cf1e342123ee79b6b673a5afeec4bf8d136ce8d

typo3/sysext/dbal/class.ux_t3lib_db.php
typo3/sysext/dbal/ext_localconf.php
typo3/sysext/dbal/lib/class.tx_dbal_querycache.php

index 6f3cd6a..247ff99 100644 (file)
@@ -127,22 +127,9 @@ class ux_t3lib_DB extends t3lib_DB {
                $this->Installer = t3lib_div::makeInstance('t3lib_install');
                $this->installerSql = t3lib_div::makeInstance('t3lib_install_Sql');
 
-
-               if (TYPO3_UseCachingFramework) {
-                       tx_dbal_querycache::initializeCachingFramework();
-
-                       try {
-                               $this->queryCache = $GLOBALS['typo3CacheManager']->getCache(
-                                       'dbal'
-                               );
-                       } catch (t3lib_cache_exception_NoSuchCache $e) {
-                               tx_dbal_querycache::initDbalCache();
-
-                               $this->queryCache = $GLOBALS['typo3CacheManager']->getCache(
-                                       'dbal'
-                               );
-                       }
-               }
+               $this->queryCache =
+                               t3lib_div::makeInstance('t3lib_cache_Manager')
+                               ->getCache('dbal');
 
                // Set internal variables with configuration:
                $this->conf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal'];
index 86220e2..ecec226 100644 (file)
@@ -13,5 +13,13 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php'
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules'][] = 'EXT:dbal/class.tx_dbal_installtool.php:tx_dbal_installtool';
 
 // Register a hook for the extension manager
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/mod/tools/em/index.php']['checkDBupdates'][] = 'EXT:dbal/class.tx_dbal_em.php:tx_dbal_em'; 
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/mod/tools/em/index.php']['checkDBupdates'][] = 'EXT:dbal/class.tx_dbal_em.php:tx_dbal_em';
+
+       // Register caches if not already done in localconf.php or a previously loaded extension.
+if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal'])) {
+       $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal'] = array(
+               'backend' => 't3lib_cache_backend_TransientMemoryBackend',
+       );
+}
+
 ?>
\ No newline at end of file
index 0d1c5d2..a32a410 100644 (file)
  * @subpackage dbal
  */
 class tx_dbal_querycache {
-
-       /**
-        * Initializes the caching framework by loading the cache manager and factory
-        * into the global context.
-        *
-        * @return      void
-        */
-       public static function initializeCachingFramework() {
-               t3lib_cache::initializeCachingFramework();
-       }
-
-       /**
-        * Initializes the DBAL cache.
-        *
-        * @return      void
-        */
-       public static function initDbalCache() {
-               try {
-                       if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal'])) {
-                               $backend = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal']['backend'];
-                               $options = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal']['options'];
-                       } else {
-                               // Transient storage, will be better than nothing
-                               $backend = 't3lib_cache_backend_TransientMemoryBackend';
-                               $options = array();
-                       }
-
-                       $GLOBALS['typo3CacheFactory']->create(
-                               'dbal',
-                               't3lib_cache_frontend_VariableFrontend',
-                               $backend,
-                               $options
-                       );
-               } catch (t3lib_cache_exception_DuplicateIdentifier $e) {
-                       // Do nothing, a DBAL cache already exists
-               }
-       }
-
        /**
         * Returns a proper cache key.
         *