Index: t3lib/config_default.php
===================================================================
--- t3lib/config_default.php	(Revision 5974)
+++ t3lib/config_default.php	(Arbeitskopie)
@@ -123,19 +123,19 @@
 				'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 @@
 				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_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: t3lib/stddb/tables.sql
===================================================================
--- t3lib/stddb/tables.sql	(Revision 5974)
+++ t3lib/stddb/tables.sql	(Arbeitskopie)
@@ -124,6 +124,20 @@
 #
 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: t3lib/class.t3lib_tstemplate.php
===================================================================
--- t3lib/class.t3lib_tstemplate.php	(Revision 5974)
+++ t3lib/class.t3lib_tstemplate.php	(Arbeitskopie)
@@ -262,15 +262,23 @@
 	 */
 	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 @@
 			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: t3lib/class.t3lib_befunc.php
===================================================================
--- t3lib/class.t3lib_befunc.php	(Revision 5974)
+++ t3lib/class.t3lib_befunc.php	(Arbeitskopie)
@@ -1241,12 +1241,23 @@
 	 * @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 @@
 	 * @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: t3lib/class.t3lib_cache.php
===================================================================
--- t3lib/class.t3lib_cache.php	(Revision 5974)
+++ t3lib/class.t3lib_cache.php	(Arbeitskopie)
@@ -31,8 +31,25 @@
  * @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
 	 *
 	 * @return	void
@@ -88,6 +105,35 @@
 				// 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: t3lib/class.t3lib_page.php
===================================================================
--- t3lib/class.t3lib_page.php	(Revision 5974)
+++ t3lib/class.t3lib_page.php	(Arbeitskopie)
@@ -971,16 +971,28 @@
 	 * @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 @@
 	 * @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: t3lib/class.t3lib_div.php
===================================================================
--- t3lib/class.t3lib_div.php	(Revision 5974)
+++ t3lib/class.t3lib_div.php	(Arbeitskopie)
@@ -2518,11 +2518,12 @@
 			$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: t3lib/class.t3lib_tsfebeuserauth.php
===================================================================
--- t3lib/class.t3lib_tsfebeuserauth.php	(Revision 5974)
+++ t3lib/class.t3lib_tsfebeuserauth.php	(Arbeitskopie)
@@ -373,10 +373,15 @@
 	 * @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: t3lib/class.t3lib_tcemain.php
===================================================================
--- t3lib/class.t3lib_tcemain.php	(Revision 5974)
+++ t3lib/class.t3lib_tcemain.php	(Arbeitskopie)
@@ -7123,18 +7123,23 @@
 
 						// 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'
+							);
 
-						$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)).')');
 
-						$pageIds = $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache);
-						foreach ($pageIds as $pageId) {
-							$pageCache->flushByTag('pageId_' . $pageId);
-							$pageSectionCache->flushByTag('pageId_' . $pageId);
 						}
 					}
 				}
@@ -7204,11 +7209,23 @@
 			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 @@
 
 					// 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 @@
 	 * @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: typo3/init.php
===================================================================
--- typo3/init.php	(Revision 5974)
+++ typo3/init.php	(Arbeitskopie)
@@ -195,15 +195,16 @@
 // Initializing the Caching System
 // ***********************************
 
-$typo3CacheManager = t3lib_div::makeInstance('t3lib_cache_Manager');
-$typo3CacheFactory = t3lib_div::makeInstance('t3lib_cache_Factory');
-$typo3CacheFactory->setCacheManager($typo3CacheManager);
+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);
-
+	t3lib_cache::initPageCache();
+	t3lib_cache::initPageSectionCache();
+	t3lib_cache::initContentHashCache();
+	unset($cacheFactoryClass);
+}
 // *************************
 // CLI dispatch processing
 // *************************
Index: typo3/sysext/cms/ext_tables.sql
===================================================================
--- typo3/sysext/cms/ext_tables.sql	(Revision 5974)
+++ typo3/sysext/cms/ext_tables.sql	(Arbeitskopie)
@@ -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: typo3/sysext/cms/tslib/class.tslib_fe.php
===================================================================
--- typo3/sysext/cms/tslib/class.tslib_fe.php	(Revision 5974)
+++ typo3/sysext/cms/tslib/class.tslib_fe.php	(Arbeitskopie)
@@ -461,7 +461,9 @@
 			}
 		}
 
-		$this->initCaches();
+		if (TYPO3_UseCachingFramework) {
+			$this->initCaches();
+		}
 	}
 
 	/**
@@ -591,28 +593,30 @@
 	 * @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();
+		}
 	}
 
 	/**
@@ -1878,9 +1882,8 @@
 					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'];
@@ -1906,11 +1909,31 @@
 	 * @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;
 	}
 
 	/**
@@ -2765,33 +2788,55 @@
 	 * @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);
+
+				$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);
 		}
-
-		$this->pageCache->set(
-			$cacheData['hash'],
-			$cacheData,
-			$this->pageCacheTags,
-			$cacheData['expires'] - $GLOBALS['EXEC_TIME']
-		);
 	}
 
 	/**
@@ -2800,9 +2845,36 @@
 	 * @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;
+			}
+		}
+	}
+
 	/**
 	 * Clears cache content for a list of page ids
 	 *
@@ -2810,10 +2882,13 @@
 	 * @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: typo3/sysext/cms/tslib/class.tslib_fetce.php
===================================================================
--- typo3/sysext/cms/tslib/class.tslib_fetce.php	(Revision 5974)
+++ typo3/sysext/cms/tslib/class.tslib_fetce.php	(Arbeitskopie)
@@ -269,11 +269,13 @@
 		$cacheCmd = intval($cacheCmd);
 
 		if ($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);
+			}
 
-			$GLOBALS['typo3CacheManager']->getCache('cache_pages')->flushByTag(
-				'pageId_' . $cacheCmd
-			);
-
 			if ($cacheCmd == intval($GLOBALS['TSFE']->id)) {
 					// Setting no_cache true if the cleared-cache page is the current page!
 				$GLOBALS['TSFE']->set_no_cache();
