Fixed bug #11505: TYPO3 4.3 is slower than 4.2 -> re-implement native db caching...
authorRupert Germann <rupi@gmx.li>
Fri, 18 Sep 2009 12:47:26 +0000 (12:47 +0000)
committerRupert Germann <rupi@gmx.li>
Fri, 18 Sep 2009 12:47:26 +0000 (12:47 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5978 709f56b5-9817-0410-a4d7-c38de5d9e867

14 files changed:
ChangeLog
t3lib/class.t3lib_befunc.php
t3lib/class.t3lib_cache.php
t3lib/class.t3lib_div.php
t3lib/class.t3lib_page.php
t3lib/class.t3lib_tcemain.php
t3lib/class.t3lib_tsfebeuserauth.php
t3lib/class.t3lib_tstemplate.php
t3lib/config_default.php
t3lib/stddb/tables.sql
typo3/init.php
typo3/sysext/cms/ext_tables.sql
typo3/sysext/cms/tslib/class.tslib_fe.php
typo3/sysext/cms/tslib/class.tslib_fetce.php

index 6b8b95a..ee18a4c 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 2009-09-18  Rupert Germann  <rupi@gmx.li>
 
        * Fixed bug #11990: Optimize output of TCEforms suggest results (thanks to Steffen Gebert)
+       * Fixed bug #11505: TYPO3 4.3 is slower than 4.2 -> re-implement native db caching and make the
+               use of the caching framework configurable. !!! DB update required
 
 2009-09-18  Oliver Hader  <oliver@typo3.org>
 
index 834ecae..6e988c2 100644 (file)
@@ -1241,12 +1241,23 @@ final class t3lib_BEfunc {
         * @return      void
         */
        public static function storeHash($hash, $data, $ident) {
-               $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
-                       $hash,
-                       $data,
-                       array('ident_' . $ident),
-                       0 // unlimited lifetime
-               );
+               if (TYPO3_UseCachingFramework) {
+                       $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
+                               $hash,
+                               $data,
+                               array('ident_' . $ident),
+                               0 // unlimited lifetime
+                       );
+               } else {
+                       $insertFields = array(
+                               'hash' => $hash,
+                               'content' => $data,
+                               'ident' => $ident,
+                               'tstamp' => $GLOBALS['EXEC_TIME']
+                       );
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
+                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
+               }
        }
 
        /**
@@ -1258,16 +1269,26 @@ final class t3lib_BEfunc {
         * @param       string          The hash-string which was used to store the data value
         * @return      string
         */
-       public static function getHash($hash) {
+       public static function getHash($hash, $expTime = 0) {
                $hashContent = null;
+               if (TYPO3_UseCachingFramework) {
+                       $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+                       $cacheEntry = $contentHashCache->get($hash);
 
-               $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
-               $cacheEntry = $contentHashCache->get($hash);
+                       if ($cacheEntry) {
+                               $hashContent = $cacheEntry;
+                       }
+               } else {
+                       $expTime = intval($expTime);
+                       if ($expTime) {
+                               $whereAdd = ' AND tstamp > '.(time()-$expTime);
+                       }
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
+                       $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
 
-               if ($cacheEntry) {
-                       $hashContent = $cacheEntry;
+                       $hashContent =  (is_array($row) ? $row['content'] : null);
                }
-
                return $hashContent;
        }
 
index 0547b90..efbeeee 100644 (file)
  * @subpackage t3lib
  */
 class t3lib_cache {
+       /**
+        * @var boolean
+        */
+       protected static $isCachingFrameworkInitialized;
+
+       /**
+        * Initializes the caching framework by loading the cache manager and factory
+        * into the global context.
+        *
+        * @return      void
+        */
+       public static function initializeCachingFramework() {
+               $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
@@ -88,6 +105,35 @@ 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() {
+               return (bool)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
+                       );
+               }
+       }
 }
 
 
index a4165fc..693961b 100644 (file)
@@ -2518,11 +2518,12 @@ final class t3lib_div {
                        $array = $firstLevelCache[$identifier];
                } else {
                                // look up in second level cache
-                       $array = $GLOBALS['typo3CacheManager']->getCache('cache_hash')->get($identifier);
+                       $cacheContent = t3lib_pageSelect::getHash($identifier, 0);
+                       $array = unserialize($cacheContent);
+
                        if ($array === false) {
                                $array = self::xml2arrayProcess($string, $NSprefix, $reportDocTag);
-                                       // store content in second level cache
-                               $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set($identifier, $array, array('ident_xml2array'), 0);
+                               t3lib_pageSelect::storeHash($identifier, serialize($array), 'ident_xml2array');
                        }
                                // store content in first level cache
                        $firstLevelCache[$identifier] = $array;
index 514addf..cbf6f4f 100644 (file)
@@ -971,16 +971,28 @@ class t3lib_pageSelect {
         * @return      string          The "content" field of the "cache_hash" cache entry.
         * @see tslib_TStemplate::start(), storeHash()
         */
-       public static function getHash($hash)   {
+       public static function getHash($hash, $expTime = 0)     {
                $hashContent = null;
 
-               $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
-               $cacheEntry = $contentHashCache->get($hash);
+               if (TYPO3_UseCachingFramework) {
+                       $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+                       $cacheEntry = $contentHashCache->get($hash);
 
-               if ($cacheEntry) {
-                       $hashContent = $cacheEntry;
+                       if ($cacheEntry) {
+                               $hashContent = $cacheEntry;
+                       }
+               } else {
+                       $expTime = intval($expTime);
+                       if ($expTime) {
+                               $whereAdd = ' AND tstamp > '.($GLOBALS['ACCESS_TIME']-$expTime);
+                       }
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
+                       $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                       if ($row)       {
+                               $hashContent = $row['content'];
+                       }
                }
-
                return $hashContent;
        }
 
@@ -997,12 +1009,23 @@ class t3lib_pageSelect {
         * @see tslib_TStemplate::start(), getHash()
         */
        public static function storeHash($hash, $data, $ident, $lifetime = 0) {
-               $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
-                       $hash,
-                       $data,
-                       array('ident_' . $ident),
-                       $lifetime
-               );
+               if (TYPO3_UseCachingFramework) {
+                       $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
+                               $hash,
+                               $data,
+                               array('ident_' . $ident),
+                               $lifetime
+                       );
+               } else {
+                       $insertFields = array(
+                               'hash' => $hash,
+                               'content' => $data,
+                               'ident' => $ident,
+                               'tstamp' => $GLOBALS['EXEC_TIME']
+                       );
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
+                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
+               }
        }
 
        /**
index aa45c2b..a827f05 100644 (file)
@@ -7123,18 +7123,23 @@ State was change by %s (username: %s)
 
                                                // Delete cache for selected pages:
                                        if (is_array($list_cache))      {
+                                               if (TYPO3_UseCachingFramework) {
+                                                       $pageCache = $GLOBALS['typo3CacheManager']->getCache(
+                                                               'cache_pages'
+                                                       );
+                                                       $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache(
+                                                               'cache_pagesection'
+                                                       );
+
+                                                       $pageIds = $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache);
+                                                       foreach ($pageIds as $pageId) {
+                                                               $pageCache->flushByTag('pageId_' . $pageId);
+                                                               $pageSectionCache->flushByTag('pageId_' . $pageId);
+                                                       }
+                                               } else {
+                                                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')');
+                                                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')');
 
-                                               $pageCache = $GLOBALS['typo3CacheManager']->getCache(
-                                                       'cache_pages'
-                                               );
-                                               $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache(
-                                                       'cache_pagesection'
-                                               );
-
-                                               $pageIds = $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache);
-                                               foreach ($pageIds as $pageId) {
-                                                       $pageCache->flushByTag('pageId_' . $pageId);
-                                                       $pageSectionCache->flushByTag('pageId_' . $pageId);
                                                }
                                        }
                                }
@@ -7204,11 +7209,23 @@ State was change by %s (username: %s)
                        case 'all':
                                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all'))   {
 
-                                               // clear all caches that use the t3lib_cache framework
-                                       $GLOBALS['typo3CacheManager']->flushCaches();
+                                               // Clear all caching framework caches if it is initialized:
+                                               // (it could be disabled by initialized by an extension)
+                                       if (t3lib_cache::isCachingFrameworkInitialized()) {
+                                               $GLOBALS['typo3CacheManager']->flushCaches();
+                                       }
 
-                                       if (t3lib_extMgm::isLoaded('cms'))      {
-                                               $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_treelist', '');
+                                       if (TYPO3_UseCachingFramework) {
+                                               if (t3lib_extMgm::isLoaded('cms'))      {
+                                                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_treelist', '');
+                                               }
+                                       } else {
+                                               if (t3lib_extMgm::isLoaded('cms'))      {
+                                                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_treelist', '');
+                                                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection','');
+                                               }
+                                               $this->internal_clearPageCache();
+                                               $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash','');
                                        }
 
                                                // Clearing additional cache tables:
@@ -7250,16 +7267,23 @@ State was change by %s (username: %s)
 
                                        // Delete cache for selected pages:
                                if (is_array($list_cache)) {
-                                       $pageCache = $GLOBALS['typo3CacheManager']->getCache(
-                                               'cache_pages'
-                                       );
-                                       $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache(
-                                               'cache_pagesection'
-                                       );
 
-                                       foreach ($list_cache as $pageId) {
-                                               $pageCache->flushByTag('pageId_' . (int) $pageId);
-                                               $pageSectionCache->flushByTag('pageId_' . (int) $pageId);
+                                       if (TYPO3_UseCachingFramework) {
+                                               $pageCache = $GLOBALS['typo3CacheManager']->getCache(
+                                                       'cache_pages'
+                                               );
+                                               $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache(
+                                                       'cache_pagesection'
+                                               );
+
+                                               foreach ($list_cache as $pageId) {
+                                                       $pageCache->flushByTag('pageId_' . (int) $pageId);
+                                                       $pageSectionCache->flushByTag('pageId_' . (int) $pageId);
+                                               }
+                                       } else {
+                                               $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')');
+                                               $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')');  // Originally, cache_pagesection was not cleared with cache_pages!
+
                                        }
                                }
                        }
@@ -7420,8 +7444,21 @@ State was change by %s (username: %s)
         * @return      void
         */
        function internal_clearPageCache() {
-               if (t3lib_extMgm::isLoaded('cms')) {
-                       $GLOBALS['typo3CacheManager']->getCache('cache_pages')->flush();
+               if (TYPO3_UseCachingFramework) {
+                       if (t3lib_extMgm::isLoaded('cms')) {
+                               $GLOBALS['typo3CacheManager']->getCache('cache_pages')->flush();
+                       }
+               } else {
+                       if (t3lib_extMgm::isLoaded('cms'))      {
+                               if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageCacheToExternalFiles']) {
+                                       $cacheDir = PATH_site.'typo3temp/cache_pages';
+                                       $retVal = t3lib_div::rmdir($cacheDir,true);
+                                       if (!$retVal) {
+                                               t3lib_div::sysLog('Could not remove page cache files in "'.$cacheDir.'"','Core/t3lib_tcemain',2);
+                                       }
+                               }
+                               $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','');
+                       }
                }
        }
 
index 53aabc2..bfd73de 100644 (file)
@@ -373,10 +373,15 @@ class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth {
         * @return      integer         The number of pages for this page in the table "cache_pages"
         */
        public function extGetNumberOfCachedPages($pageId) {
-               $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
-               $pageCacheEntries = $pageCache->getByTag('pageId_' . (int) $pageId);
-
-               return count($pageCacheEntries);
+               if (TYPO3_UseCachingFramework) {
+                       $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+                       $pageCacheEntries = $pageCache->getByTag('pageId_' . (int) $pageId);
+                       $count = count($pageCacheEntries);
+               } else {
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_pages', 'page_id='.intval($pageId));
+                       list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
+               }
+               return $count;
        }
 
 
index 34a4552..1bf93c8 100644 (file)
@@ -262,15 +262,23 @@ class t3lib_TStemplate    {
         */
        function getCurrentPageData() {
                $currentPageData = false;
-               $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
-               /* @var $pageSectionCache t3lib_cache_AbstractCache */
+               if (TYPO3_UseCachingFramework) {
+                       $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+                       /* @var $pageSectionCache t3lib_cache_AbstractCache */
 
-               $cacheEntry = $pageSectionCache->get(
-                       intval($GLOBALS['TSFE']->id) . '_' . t3lib_div::md5int($GLOBALS['TSFE']->MP)
-               );
+                       $cacheEntry = $pageSectionCache->get(
+                               intval($GLOBALS['TSFE']->id) . '_' . t3lib_div::md5int($GLOBALS['TSFE']->MP)
+                       );
 
-               if ($cacheEntry) {
-                       $currentPageData = unserialize($cacheEntry);
+                       if ($cacheEntry) {
+                               $currentPageData = unserialize($cacheEntry);
+                       }
+               } else {
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                               'content', 'cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
+                       if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                               $currentPageData = unserialize($row['content']);
+                       }
                }
 
                return $currentPageData;        // 2008-02-03 / Stucki: Notice that $this->currentPageData is not used anymore!
@@ -400,20 +408,30 @@ class t3lib_TStemplate    {
                        unset($cc['match']);
 
                        if (!$isCached && !$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) {      // Only save the data if we're not simulating by hidden/starttime/endtime
-                               $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
-                               /* @var $pageSectionCache t3lib_cache_AbstractCache */
-
                                $mpvarHash = t3lib_div::md5int($GLOBALS['TSFE']->MP);
-
-                               $pageSectionCache->set(
-                                       intval($GLOBALS['TSFE']->id) . '_' . $mpvarHash,
-                                       serialize($cc),
-                                       array(
-                                               'pageId_' . intval($GLOBALS['TSFE']->id),
-                                               'mpvarHash_' . $mpvarHash
-                                       )
-                               );
-
+                               if (TYPO3_UseCachingFramework) {
+                                       $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+                                       /* @var $pageSectionCache t3lib_cache_AbstractCache */
+                                       $pageSectionCache->set(
+                                               intval($GLOBALS['TSFE']->id) . '_' . $mpvarHash,
+                                               serialize($cc),
+                                               array(
+                                                       'pageId_' . intval($GLOBALS['TSFE']->id),
+                                                       'mpvarHash_' . $mpvarHash
+                                               )
+                                       );
+                               } else {
+                                       $dbFields = array(
+                                               'content' => serialize($cc),
+                                               'tstamp' => $GLOBALS['EXEC_TIME']
+                                       );
+                                       $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . $mpvarHash, $dbFields);
+                                       if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) {
+                                               $dbFields['page_id'] = intval($GLOBALS['TSFE']->id);
+                                               $dbFields['mpvar_hash'] = $mpvarHash;
+                                               $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $dbFields);
+                                       }
+                               }
                        }
                                // If everything OK.
                        if ($this->rootId && $this->rootLine && $this->setup)   {
index deeb7bb..cac9d86 100644 (file)
@@ -123,19 +123,19 @@ $TYPO3_CONF_VARS = Array(
                                'cache_hash' => array(
                                        'backend' => 't3lib_cache_backend_DbBackend',
                                        'options' => array(
-                                               'cacheTable' => 'cache_hash'
+                                               'cacheTable' => 'cachingframework_cache_hash'
                                        )
                                ),
                                'cache_pages' => array(
                                        'backend' => 't3lib_cache_backend_DbBackend',
                                        'options' => array(
-                                               'cacheTable' => 'cache_pages'
+                                               'cacheTable' => 'cachingframework_cache_pages'
                                        )
                                ),
                                'cache_pagesection' => array(
                                        'backend' => 't3lib_cache_backend_DbBackend',
                                        'options' => array(
-                                               'cacheTable' => 'cache_pagesection'
+                                               'cacheTable' => 'cachingframework_cache_pagesection'
                                        )
                                )
                                /*
@@ -151,7 +151,8 @@ $TYPO3_CONF_VARS = Array(
                                You need to have memcached installed as a daemon and also as a PHP extension!
                                */
                        )
-               )
+               ),
+               'useCachingFramework' => 0,                             // Boolean: Enable this if you want to use the caching framework by default for the core caches cache_pages, cache_pagesection and cache_hash.
        ),
        'EXT' => Array (        // Options related to the Extension Management
                'noEdit' => 1,                                                  // Boolean: If set, the Extension Manager does NOT allow extension files to be edited! (Otherwise both local and global extensions can be edited.)
@@ -522,6 +523,8 @@ if ($TYPO3_LOADED_EXT['_CACHEFILE'])        {
 }
 if (TYPO3_MODE=='FE' && is_object($TT)) $TT->pull();
 
+       // Define disposal of caching framewor for core caches:
+define('TYPO3_UseCachingFramework', (bool)$GLOBALS['TYPO3_CONF_VARS']['SYS']['useCachingFramework']);
        // Define "TYPO3_DLOG" constant
 define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
 
index 19b0fe4..e7d3eec 100644 (file)
@@ -124,6 +124,20 @@ CREATE TABLE cache_extensions (
 #
 CREATE TABLE cache_hash (
   id int(11) unsigned NOT NULL auto_increment,
+  hash varchar(32) DEFAULT '' NOT NULL,
+  content mediumtext,
+  tstamp int(11) unsigned DEFAULT '0' NOT NULL,
+  ident varchar(32) DEFAULT '' NOT NULL,
+  PRIMARY KEY (id)
+  KEY hash (hash)
+) ENGINE=InnoDB;
+
+
+#
+# Table structure for table 'cachingframework_cache_hash'
+#
+CREATE TABLE cachingframework_cache_hash (
+  id int(11) unsigned NOT NULL auto_increment,
   identifier varchar(250) DEFAULT '' NOT NULL,
   crdate int(11) unsigned DEFAULT '0' NOT NULL,
   content mediumtext,
index f52f7b2..8d1fdf8 100644 (file)
@@ -195,15 +195,16 @@ $PARSETIME_START = t3lib_div::milliseconds();             // Is set to the system time in m
 // Initializing the Caching System
 // ***********************************
 
-$typo3CacheManager = t3lib_div::makeInstance('t3lib_cache_Manager');
-$typo3CacheFactory = t3lib_div::makeInstance('t3lib_cache_Factory');
-$typo3CacheFactory->setCacheManager($typo3CacheManager);
-
-t3lib_cache::initPageCache();
-t3lib_cache::initPageSectionCache();
-t3lib_cache::initContentHashCache();
-unset($cacheFactoryClass);
-
+if (TYPO3_UseCachingFramework) {
+       $typo3CacheManager = t3lib_div::makeInstance('t3lib_cache_Manager');
+       $typo3CacheFactory = t3lib_div::makeInstance('t3lib_cache_Factory');
+       $typo3CacheFactory->setCacheManager($typo3CacheManager);
+
+       t3lib_cache::initPageCache();
+       t3lib_cache::initPageSectionCache();
+       t3lib_cache::initContentHashCache();
+       unset($cacheFactoryClass);
+}
 // *************************
 // CLI dispatch processing
 // *************************
index cc29c4c..281a893 100755 (executable)
@@ -8,28 +8,71 @@
 #
 CREATE TABLE cache_pages (
   id int(11) unsigned NOT NULL auto_increment,
+  hash varchar(32) DEFAULT '' NOT NULL,
+  page_id int(11) unsigned DEFAULT '0' NOT NULL,
+  reg1 int(11) unsigned DEFAULT '0' NOT NULL,
+  HTML mediumtext,
+  temp_content int(1) DEFAULT '0' NOT NULL,
+  tstamp int(11) unsigned DEFAULT '0' NOT NULL,
+  expires int(10) unsigned DEFAULT '0' NOT NULL,
+  cache_data mediumtext,
+  KEY page_id (page_id),
+  KEY sel (hash,page_id),
+  PRIMARY KEY (id)
+) ENGINE=InnoDB;
+
+
+#
+# Table structure for table 'cache_pagesection'
+#
+CREATE TABLE cache_pagesection (
+  page_id int(11) unsigned DEFAULT '0' NOT NULL,
+  mpvar_hash int(11) unsigned DEFAULT '0' NOT NULL,
+  content text,
+  tstamp int(11) unsigned DEFAULT '0' NOT NULL,
+  PRIMARY KEY (page_id,mpvar_hash)
+) ENGINE=InnoDB;
+
+
+
+
+#
+# Table structure for table 'cachingframework_cache_pages'
+#
+CREATE TABLE cachingframework_cache_pages (
+  id int(11) unsigned NOT NULL auto_increment,
   identifier varchar(250) DEFAULT '' NOT NULL,
   crdate int(11) unsigned DEFAULT '0' NOT NULL,
+  page_id int(11) unsigned DEFAULT '0' NOT NULL,
+  reg1 int(11) unsigned DEFAULT '0' NOT NULL,
   content mediumtext,
   tags mediumtext,
   lifetime int(11) unsigned DEFAULT '0' NOT NULL,
-  PRIMARY KEY (id),
-  KEY cache_id (identifier)
+  temp_content int(1) DEFAULT '0' NOT NULL,
+  tstamp int(11) unsigned DEFAULT '0' NOT NULL,
+  expires int(10) unsigned DEFAULT '0' NOT NULL,
+  cache_data mediumblob,
+  KEY page_id (page_id),
+  KEY sel (identifier,page_id),
+  PRIMARY KEY (id)
 ) ENGINE=InnoDB;
 
 
 #
-# Table structure for table 'cache_pagesection'
+# Table structure for table 'cachingframework_cache_pagesection'
 #
-CREATE TABLE cache_pagesection (
+CREATE TABLE cachingframework_cache_pagesection (
   id int(11) unsigned NOT NULL auto_increment,
   identifier varchar(250) DEFAULT '' NOT NULL,
   crdate int(11) unsigned DEFAULT '0' NOT NULL,
   content mediumtext,
   tags mediumtext,
   lifetime int(11) unsigned DEFAULT '0' NOT NULL,
+  page_id int(11) unsigned DEFAULT '0' NOT NULL,
+  mpvar_hash int(11) unsigned DEFAULT '0' NOT NULL,
   PRIMARY KEY (id),
-  KEY cache_id (identifier)
+  KEY cache_id (identifier),
+  KEY sel (page_id,mpvar_hash)
 ) ENGINE=InnoDB;
 
 
index dd7dfe8..79d3995 100644 (file)
                        }
                }
 
-               $this->initCaches();
+               if (TYPO3_UseCachingFramework) {
+                       $this->initCaches();
+               }
        }
 
        /**
         * @return      void
         */
        protected function initCaches() {
-               $GLOBALS['TT']->push('Initializing the Caching System','');
+               if (TYPO3_UseCachingFramework) {
+                       $GLOBALS['TT']->push('Initializing the Caching System','');
 
-               $GLOBALS['typo3CacheManager'] = t3lib_div::makeInstance('t3lib_cache_Manager');
-               $GLOBALS['typo3CacheFactory'] = t3lib_div::makeInstance('t3lib_cache_Factory');
-               $GLOBALS['typo3CacheFactory']->setCacheManager($GLOBALS['typo3CacheManager']);
+                       $GLOBALS['typo3CacheManager'] = t3lib_div::makeInstance('t3lib_cache_Manager');
+                       $GLOBALS['typo3CacheFactory'] = t3lib_div::makeInstance('t3lib_cache_Factory');
+                       $GLOBALS['typo3CacheFactory']->setCacheManager($GLOBALS['typo3CacheManager']);
 
-               try {
-                       $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
-                               'cache_pages'
-                       );
-               } catch(t3lib_cache_exception_NoSuchCache $e) {
-                       t3lib_cache::initPageCache();
+                       try {
+                               $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
+                                       'cache_pages'
+                               );
+                       } catch(t3lib_cache_exception_NoSuchCache $e) {
+                               t3lib_cache::initPageCache();
 
-                       $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
-                               'cache_pages'
-                       );
-               }
+                               $this->pageCache = $GLOBALS['typo3CacheManager']->getCache(
+                                       'cache_pages'
+                               );
+                       }
 
-               t3lib_cache::initPageSectionCache();
-               t3lib_cache::initContentHashCache();
+                       t3lib_cache::initPageSectionCache();
+                       t3lib_cache::initContentHashCache();
 
-               $GLOBALS['TT']->pull();
+                       $GLOBALS['TT']->pull();
+               }
        }
 
        /**
                                        if (is_array($row)) {
                                                        // Release this lock
                                                $this->releasePageGenerationLock($this->pages_lockObj);
-
                                                $this->config = (array)unserialize($row['cache_data']);         // Fetches the lowlevel config stored with the cached data
-                                               $this->content = $row['HTML'];  // Getting the content
+                                               $this->content = (TYPO3_UseCachingFramework ? $row['content'] : $row['HTML']);  // Getting the content
                                                $this->tempContent = $row['temp_content'];      // Flag for temp content
                                                $this->cacheContentFlag = 1;    // Setting flag, so we know, that some cached content has been loaded
                                                $this->cacheExpires = $row['expires'];
         * @return      array           Cached row, if any. Otherwise void.
         */
        function getFromCache_queryRow() {
-               $GLOBALS['TT']->push('Cache Query', '');
-               $cachedPage = $this->pageCache->get($this->newHash);
-               $GLOBALS['TT']->pull();
+               if (TYPO3_UseCachingFramework) {
+                       $GLOBALS['TT']->push('Cache Query', '');
+                       $row = $this->pageCache->get($this->newHash);
+                       $GLOBALS['TT']->pull();
+               } else {
+                       $GLOBALS['TT']->push('Cache Query','');
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                               'S.*',
+                               'cache_pages S,pages P',
+                               'S.hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->newHash, 'cache_pages').'
+                                       AND S.page_id=P.uid
+                                       AND S.expires > '.intval($GLOBALS['ACCESS_TIME']).'
+                                       AND P.deleted=0
+                                       AND P.hidden=0
+                                       AND P.starttime<='.intval($GLOBALS['ACCESS_TIME']).'
+                                       AND (P.endtime=0 OR P.endtime>'.intval($GLOBALS['ACCESS_TIME']).')'
+                       );
+                       $GLOBALS['TT']->pull();
 
-               return $cachedPage;
+                       if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                               $this->pageCachePostProcess($row,'get');
+                       }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+               }
+               return $row;
        }
 
        /**
         * @see realPageCacheContent(), tempPageCacheContent()
         */
        function setPageCacheContent($content, $data, $expirationTstamp) {
-               $cacheData = array(
-                       'hash'         => $this->newHash,
-                       'page_id'      => $this->id,
-                       'HTML'         => $content,
-                       'temp_content' => $this->tempContent,
-                       'cache_data'   => serialize($data),
-                       'expires'      => $expirationTstamp,
-                       'tstamp'       => $GLOBALS['EXEC_TIME']
-               );
 
-               $this->cacheExpires = $expirationTstamp;
+               if (TYPO3_UseCachingFramework) {
+                       $cacheData = array(
+                               'identifier'    => $this->newHash,
+                               'page_id'               => $this->id,
+                               'content'                       => $content,
+                               'temp_content'  => $this->tempContent,
+                               'cache_data'    => serialize($data),
+                               'expires'               => $expirationTstamp,
+                               'tstamp'                => $GLOBALS['EXEC_TIME']
+                       );
 
-               $this->pageCacheTags[] = 'pageId_' . $cacheData['page_id'];
+                       $this->cacheExpires = $expirationTstamp;
 
-               if ($this->page_cache_reg1) {
-                       $reg1 = intval($this->page_cache_reg1);
+                       $this->pageCacheTags[] = 'pageId_' . $cacheData['page_id'];
 
-                       $cacheData['reg1']     = $reg1;
-                       $this->pageCacheTags[] = 'reg1_' . $reg1;
-               }
+                       if ($this->page_cache_reg1) {
+                               $reg1 = intval($this->page_cache_reg1);
 
-               $this->pageCache->set(
-                       $cacheData['hash'],
-                       $cacheData,
-                       $this->pageCacheTags,
-                       $cacheData['expires'] - $GLOBALS['EXEC_TIME']
-               );
+                               $cacheData['reg1']     = $reg1;
+                               $this->pageCacheTags[] = 'reg1_' . $reg1;
+                       }
+
+                       $this->pageCache->set(
+                               $this->newHash,
+                               $cacheData,
+                               $this->pageCacheTags,
+                               $expirationTstamp - $GLOBALS['EXEC_TIME']
+                       );
+               } else {
+                       $this->clearPageCacheContent();
+                       $insertFields = array(
+                               'hash' => $this->newHash,
+                               'page_id' => $this->id,
+                               'HTML' => $content,
+                               'temp_content' => $this->tempContent,
+                               'cache_data' => serialize($data),
+                               'expires' => $expirationTstamp,
+                               'tstamp' => $GLOBALS['EXEC_TIME']
+                       );
+
+                       $this->cacheExpires = $expirationTstamp;
+
+                       if ($this->page_cache_reg1)     {
+                               $insertFields['reg1'] = intval($this->page_cache_reg1);
+                       }
+                       $this->pageCachePostProcess($insertFields,'set');
+                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pages', $insertFields);
+               }
        }
 
        /**
         * @return      void
         */
        function clearPageCacheContent() {
-               $this->pageCache->remove($this->newHash);
+               if (TYPO3_UseCachingFramework) {
+                       $this->pageCache->remove($this->newHash);
+               } else {
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->newHash, 'cache_pages'));
+               }
+       }
+
+       /**
+        * Post processing page cache rows for both get and set.
+        *
+        * @param       array           Input "cache_pages" row, passed by reference!
+        * @param       string          Type of operation, either "get" or "set"
+        * @return      void
+        */
+       function pageCachePostProcess(&$row,$type)      {
+
+               if ($this->TYPO3_CONF_VARS['FE']['pageCacheToExternalFiles'])   {
+                       $cacheFileName = PATH_site.'typo3temp/cache_pages/'.$row['hash']{0}.$row['hash']{1}.'/'.$row['hash'].'.html';
+                       switch((string)$type)   {
+                               case 'get':
+                                       $row['content'] = @is_file($cacheFileName) ? t3lib_div::getUrl($cacheFileName) : '<!-- CACHING ERROR, sorry -->';
+                               break;
+                               case 'set':
+                                       t3lib_div::writeFileToTypo3tempDir($cacheFileName,$row['content']);
+                                       $row['content'] = '';
+                               break;
+                       }
+               }
        }
 
        /**
         * @return      void
         */
        function clearPageCacheContent_pidList($pidList) {
-               $pageIds = t3lib_div::trimExplode(',', $pidList);
-
-               foreach ($pageIds as $pageId) {
-                       $this->pageCache->flushByTag('pageId_' . (int) $pageId);
+               if (!TYPO3_UseCachingFramework) {
+                       $pageIds = t3lib_div::trimExplode(',', $pidList);
+                       foreach ($pageIds as $pageId) {
+                               $this->pageCache->flushByTag('pageId_' . (int) $pageId);
+                       }
+               } else {
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($pidList).')');
                }
        }
 
index 3744dc4..cf4e60f 100644 (file)
@@ -269,10 +269,12 @@ class tslib_feTCE {
                $cacheCmd = intval($cacheCmd);
 
                if ($cacheCmd)  {
-
-                       $GLOBALS['typo3CacheManager']->getCache('cache_pages')->flushByTag(
-                               'pageId_' . $cacheCmd
-                       );
+                       if (TYPO3_UseCachingFramework) {
+                               $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+                               $pageCache->flushByTag('pageId_' . $cacheCmd);
+                       } else {
+                               $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id = ' . $cacheCmd);
+                       }
 
                        if ($cacheCmd == intval($GLOBALS['TSFE']->id)) {
                                        // Setting no_cache true if the cleared-cache page is the current page!