Index: t3lib/config_default.php
===================================================================
--- t3lib/config_default.php	(Revision 5911)
+++ t3lib/config_default.php	(Arbeitskopie)
@@ -123,19 +123,22 @@
 				'cache_hash' => array(
 					'backend' => 't3lib_cache_backend_DbBackend',
 					'options' => array(
-						'cacheTable' => 'cache_hash'
+						'cacheTable' => 'cache_hash',
+						'tagsTable' => 'cache_hash_tags',
 					)
 				),
 				'cache_pages' => array(
 					'backend' => 't3lib_cache_backend_DbBackend',
 					'options' => array(
-						'cacheTable' => 'cache_pages'
+						'cacheTable' => 'cache_pages',
+						'tagsTable' => 'cache_pages_tags',
 					)
 				),
 				'cache_pagesection' => array(
 					'backend' => 't3lib_cache_backend_DbBackend',
 					'options' => array(
-						'cacheTable' => 'cache_pagesection'
+						'cacheTable' => 'cache_pagesection',
+						'tagsTable' => 'cache_pagesection_tags',
 					)
 				)
 				/*
Index: t3lib/stddb/tables.sql
===================================================================
--- t3lib/stddb/tables.sql	(Revision 5911)
+++ t3lib/stddb/tables.sql	(Arbeitskopie)
@@ -124,16 +124,27 @@
 #
 CREATE TABLE cache_hash (
   id int(11) unsigned NOT NULL auto_increment,
-  identifier varchar(250) DEFAULT '' NOT NULL,
+  identifier varchar(128) DEFAULT '' NOT NULL,
   crdate 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)
 ) ENGINE=InnoDB;
 
 #
+# Table structure for table 'cache_hash_tags'
+#
+CREATE TABLE cache_hash_tags (
+  id int(11) unsigned NOT NULL auto_increment,
+  identifier varchar(128) DEFAULT '' NOT NULL,
+  tag varchar(128) DEFAULT '' NOT NULL,
+  PRIMARY KEY (id),
+  KEY cache_id (identifier),
+  KEY cache_tag (tag)
+) ENGINE=InnoDB;
+
+#
 # Table structure for table 'cache_imagesizes'
 #
 CREATE TABLE cache_imagesizes (
Index: t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php
===================================================================
--- t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php	(Revision 5911)
+++ t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php	(Arbeitskopie)
@@ -33,8 +33,41 @@
 class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend {
 
 	protected $cacheTable;
+	protected $tagsTable;
 
+	protected $identifierField;
+	protected $creationField;
+	protected $lifetimeField;
+	protected $notExpiredStatement;
+	protected $tableList;
+	protected $tableJoin;
+
 	/**
+	 * Constructs this backend
+	 *
+	 * @param mixed Configuration options - depends on the actual backend
+	 */
+	public function __construct(array $options = array()) {
+		parent::__construct($options);
+		$this->initializeCommonReferences();
+	}
+
+	/**
+	 * Initializes common references used in this backend.
+	 *
+	 * @return	void
+	 */
+	protected function initializeCommonReferences() {
+		$this->identifierField = $this->cacheTable . '.identifier';
+		$this->creationField = $this->cacheTable . '.crdate';
+		$this->lifetimeField = $this->cacheTable . '.lifetime';
+		$this->tableList = $this->cacheTable . ', ' . $this->tagsTable;
+		$this->tableJoin = $this->identifierField . ' = ' . $this->tagsTable . '.identifier';
+		$this->notExpiredStatement = '(' . $this->creationField . ' + ' . $this->lifetimeField .
+			' >= ' . $GLOBALS['EXEC_TIME'] . ' OR ' . $this->lifetimeField . ' = 0)';
+	}
+
+	/**
 	 * Saves data in a cache file.
 	 *
 	 * @param string An identifier for this specific cache entry
@@ -73,10 +106,19 @@
 				'identifier' => $entryIdentifier,
 				'crdate'     => $GLOBALS['EXEC_TIME'],
 				'content'    => $data,
-				'tags'       => implode(',', $tags),
 				'lifetime'   => $lifetime
 			)
 		);
+
+		foreach ($tags as $tag) {
+			$GLOBALS['TYPO3_DB']->exec_INSERTquery(
+				$this->tagsTable,
+				array(
+					'identifier' => $entryIdentifier,
+					'tag'        => $tag,
+				)
+			);
+		}
 	}
 
 	/**
@@ -117,7 +159,7 @@
 			'content',
 			$this->cacheTable,
 			'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable) . ' '
-				. 'AND crdate + lifetime >= ' . $GLOBALS['EXEC_TIME']
+				. 'AND crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0'
 		);
 
 		if (count($cacheEntries) == 1) {
@@ -139,8 +181,10 @@
 		$entryRemoved = false;
 
 		$res = $GLOBALS['TYPO3_DB']->exec_DELETEquery(
-			$this->cacheTable,
-			'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable)
+			$this->tableList,
+			$this->tableJoin .
+				' AND ' . $this->identifierField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable),
+			$this->tableList
 		);
 
 		if($GLOBALS['TYPO3_DB']->sql_affected_rows($res) == 1) {
@@ -161,9 +205,12 @@
 		$cacheEntryIdentifiers = array();
 
 		$cacheEntryIdentifierRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-			'identifier',
-			$this->cacheTable,
-			$this->getListQueryForTag($tag) . ' AND (crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0)'
+			$this->identifierField,
+			$this->tableList,
+			$this->getQueryForTag() .
+				' AND ' . $this->tableJoin .
+				' AND ' . $this->notExpiredStatement,
+			$this->identifierField
 		);
 
 		foreach ($cacheEntryIdentifierRows as $cacheEntryIdentifierRow) {
@@ -186,14 +233,17 @@
 		$whereClause  = array();
 
 		foreach ($tags as $tag) {
-			$whereClause[] = $this->getListQueryForTag($tag);
+			$whereClause[] = $this->getQueryForTag($tag);
 		}
-		$whereClause[] = '(crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0)';
 
+		$whereClause[] = $this->tableJoin;
+		$whereClause[] = $this->notExpiredStatement;
+
 		$cacheEntryIdentifierRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-			'identifier',
-			$this->cacheTable,
-			implode(' AND ', $whereClause)
+			$this->identifierField,
+			$this->tableList,
+			implode(' AND ', $whereClause),
+			$this->identifierField
 		);
 
 		foreach ($cacheEntryIdentifierRows as $cacheEntryIdentifierRow) {
@@ -211,6 +261,7 @@
 	 */
 	public function flush() {
 		$GLOBALS['TYPO3_DB']->sql_query('TRUNCATE ' . $this->cacheTable);
+		$GLOBALS['TYPO3_DB']->sql_query('TRUNCATE ' . $this->tagsTable);
 	}
 
 	/**
@@ -221,8 +272,10 @@
 	 */
 	public function flushByTag($tag) {
 		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
-			$this->cacheTable,
-			$this->getListQueryForTag($tag)
+			$this->tableList,
+			$this->tableJoin .
+				' AND ' . $this->getQueryForTag($tag),
+			$this->tableList
 		);
 	}
 
@@ -233,16 +286,19 @@
 	 * @return void
 	 */
 	public function flushByTags(array $tags) {
-		$listQueryConditions = array();
-		foreach ($tags as $tag) {
-			$listQueryConditions[$tag] = $this->getListQueryForTag($tag);
+		if (count($tags)) {
+			$listQueryConditions = array();
+			foreach ($tags as $tag) {
+				$listQueryConditions[$tag] = $this->getQueryForTag($tag);
+			}
+	
+			$GLOBALS['TYPO3_DB']->exec_DELETEquery(
+				$this->tableList,
+				$this->tableJoin .
+					' AND (' . implode(' OR ', $listQueryConditions) . ')',
+				$this->tableList
+			);
 		}
-
-		$listQuery = implode(' OR ', $listQueryConditions);
-		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
-			$this->cacheTable,
-			$listQuery
-		);
 	}
 
 	/**
@@ -253,8 +309,11 @@
 	 */
 	public function collectGarbage() {
 		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
-			$this->cacheTable,
-			'crdate + lifetime < ' . $GLOBALS['EXEC_TIME'] . ' AND lifetime > 0'
+			$this->tableList,
+			$this->tableJoin .
+				' AND ' . $this->cacheTable . '.crdate + ' . $this->cacheTable . '.lifetime < ' . $GLOBALS['EXEC_TIME'] .
+				' AND ' . $this->cacheTable . '.lifetime > 0',
+			$this->tableList
 		);
 	}
 
@@ -300,6 +359,7 @@
 		}
 */
 		$this->cacheTable = $cacheTable;
+		$this->initializeCommonReferences();
 	}
 
 	/**
@@ -313,6 +373,26 @@
 	}
 
 	/**
+	 * Sets the table where cache tags are stored.
+	 *
+	 * @param	string		$tagsTabls: Name of the table
+	 * @return	void
+	 */
+	public function setTagsTable($tagsTable) {
+		$this->tagsTable = $tagsTable;
+		$this->initializeCommonReferences();
+	}
+
+	/**
+	 * Gets the table where cache tags are store.
+	 *
+	 * @return	string		Name of the table storing tags
+	 */
+	public function getTagsTable() {
+		return $this->tagsTable;
+	}
+
+	/**
 	 * Gets the query to be used for selecting entries by a tag. The asterisk ("*")
 	 * is allowed as a wildcard at the beginning and the end of a tag.
 	 *
@@ -320,8 +400,18 @@
 	 * @return string the query to be used for selecting entries
 	 * @author Oliver Hader <oliver@typo3.org>
 	 */
-	protected function getListQueryForTag($tag) {
-		return str_replace('*', '%', $GLOBALS['TYPO3_DB']->listQuery('tags', $tag, $this->cacheTable));
+	protected function getQueryForTag($tag) {
+		if (strpos($tag, '*') === false) {
+			$query = $this->tagsTable . 'tag = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tag, $this->tagsTable);
+		} else {
+			$patternForLike = $GLOBALS['TYPO3_DB']->escapeStrForLike(
+				$GLOBALS['TYPO3_DB']->quoteStr($tag, $this->tagsTable),
+				$this->tagsTable
+			);
+			$query = $this->tagsTable . 'tag LIKE \'' . $patternForLike . '\'';
+		}
+
+		return $query;
 	}
 }
 
Index: t3lib/class.t3lib_db.php
===================================================================
--- t3lib/class.t3lib_db.php	(Revision 5911)
+++ t3lib/class.t3lib_db.php	(Arbeitskopie)
@@ -207,10 +207,11 @@
 	 *
 	 * @param	string		Database tablename
 	 * @param	string		WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!
+	 * @param	string		Comma list of tables to execute deletion on in multi-table context (default: '')
 	 * @return	pointer		MySQL result pointer / DBAL object
 	 */
-	function exec_DELETEquery($table,$where)	{
-		$res = mysql_query($this->DELETEquery($table,$where), $this->link);
+	function exec_DELETEquery($table, $where, $deleteTable = '') {
+		$res = mysql_query($this->DELETEquery($table,$where, $deleteTable), $this->link);
 		if ($this->debugOutput)	$this->debug('exec_DELETEquery');
 		return $res;
 	}
@@ -447,13 +448,14 @@
 	 *
 	 * @param	string		See exec_DELETEquery()
 	 * @param	string		See exec_DELETEquery()
+	 * @param	string		See exec_DELETEquery()
 	 * @return	string		Full SQL query for DELETE
 	 */
-	function DELETEquery($table,$where)	{
+	function DELETEquery($table,$where, $deleteTable = '') {
 		if (is_string($where))	{
 
 				// Table and fieldnames should be "SQL-injection-safe" when supplied to this function
-			$query = 'DELETE FROM '.$table.
+			$query = 'DELETE ' . $deleteTable . ' FROM '.$table.
 				(strlen($where)>0 ? '
 				WHERE
 					'.$where : '');
Index: typo3/sysext/cms/ext_tables.sql
===================================================================
--- typo3/sysext/cms/ext_tables.sql	(Revision 5911)
+++ typo3/sysext/cms/ext_tables.sql	(Arbeitskopie)
@@ -8,10 +8,9 @@
 #
 CREATE TABLE cache_pages (
   id int(11) unsigned NOT NULL auto_increment,
-  identifier varchar(250) DEFAULT '' NOT NULL,
+  identifier varchar(128) DEFAULT '' NOT NULL,
   crdate 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)
@@ -19,14 +18,26 @@
 
 
 #
+# Table structure for table 'cache_pages_tags'
+#
+CREATE TABLE cache_pages_tags (
+  id int(11) unsigned NOT NULL auto_increment,
+  identifier varchar(128) DEFAULT '' NOT NULL,
+  tag varchar(128) DEFAULT '' NOT NULL,
+  PRIMARY KEY (id),
+  KEY cache_id (identifier),
+  KEY cache_tag (tag)
+) ENGINE=InnoDB;
+
+
+#
 # Table structure for table 'cache_pagesection'
 #
 CREATE TABLE cache_pagesection (
   id int(11) unsigned NOT NULL auto_increment,
-  identifier varchar(250) DEFAULT '' NOT NULL,
+  identifier varchar(128) DEFAULT '' NOT NULL,
   crdate 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)
@@ -34,6 +45,19 @@
 
 
 #
+# Table structure for table 'cache_pagesection_tags'
+#
+CREATE TABLE cache_pagesection_tags (
+  id int(11) unsigned NOT NULL auto_increment,
+  identifier varchar(128) DEFAULT '' NOT NULL,
+  tag varchar(128) DEFAULT '' NOT NULL,
+  PRIMARY KEY (id),
+  KEY cache_id (identifier),
+  KEY cache_tag (tag)
+) ENGINE=InnoDB;
+
+
+#
 # Table structure for table 'cache_typo3temp_log'
 #
 CREATE TABLE cache_typo3temp_log (
