Index: tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendTest.php
===================================================================
--- tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendTest.php	(revision 8193)
+++ tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendTest.php	(working copy)
@@ -66,20 +66,32 @@
 	protected $testingTagsTable;
 
 	/**
-	 * Sets up this testcase
+	 * Sets up the backend used for testing
 	 *
 	 * @return void
 	 * @author Ingo Renner <ingo@typo3.org>
+	 * @author Christian Kuhn <lolli@schwarzbu.ch>
 	 */
-	public function setUp() {
-		$this->testingCacheTable = 'test_cache_dbbackend';
-		$this->testingTagsTable = 'test_cache_dbbackend_tags';
+	public function setUpBackend(array $backendOptions = array()) {
+		$defaultTestingCacheTable = 'test_cache_dbbackend';
+		$defaultTestingTagsTable = 'test_cache_dbbackend_tags';
 
+		$backendOptions = array_merge(
+			array(
+				'cacheTable' => $defaultTestingCacheTable,
+				'tagsTable' => $defaultTestingTagsTable,
+			),
+			$backendOptions
+		);
+
+		$this->testingCacheTable = $backendOptions['cacheTable'];
+		$this->testingTagsTable = $backendOptions['tagsTable'];
+
 		$GLOBALS['TYPO3_DB']->sql_query('CREATE TABLE ' . $this->testingCacheTable . ' (
 			id int(11) unsigned NOT NULL auto_increment,
 			identifier varchar(128) DEFAULT \'\' NOT NULL,
 			crdate int(11) unsigned DEFAULT \'0\' NOT NULL,
-			content mediumtext,
+			content mediumblob,
 			lifetime int(11) unsigned DEFAULT \'0\' NOT NULL,
 			PRIMARY KEY (id),
 			KEY cache_id (identifier)
@@ -98,14 +110,24 @@
 
 		$this->backend = t3lib_div::makeInstance(
 			't3lib_cache_backend_DbBackend',
-			array(
-				'cacheTable' => $this->testingCacheTable,
-				'tagsTable' => $this->testingTagsTable,
-			)
+			$backendOptions
 		);
 	}
 
 	/**
+	 * @author Ingo Renner <ingo@typo3.org>
+	 */
+	public function tearDown() {
+		$GLOBALS['TYPO3_DB']->sql_query(
+			'DROP TABLE ' . $this->testingCacheTable . ';'
+		);
+
+		$GLOBALS['TYPO3_DB']->sql_query(
+			'DROP TABLE ' . $this->testingTagsTable . ';'
+		);
+	}
+
+	/**
 	 * @test
 	 * @expectedException t3lib_cache_Exception
 	 * @author Ingo Renner <ingo@typo3.org>
@@ -120,6 +142,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function getCacheTableReturnsThePreviouslySetTable() {
+		$this->setUpBackend();
 		$this->backend->setCacheTable($this->testingCacheTable);
 		$this->assertEquals($this->testingCacheTable, $this->backend->getCacheTable(), 'getCacheTable() did not return the expected value.');
 	}
@@ -130,6 +153,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function setThrowsExceptionIfDataIsNotAString() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -150,6 +174,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function setReallySavesToTheSpecifiedTable() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -181,6 +206,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function setRemovesAnAlreadyExistingCacheEntryForTheSameIdentifier() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -212,6 +238,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function setReallySavesSpecifiedTags() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -244,9 +271,69 @@
 
 	/**
 	 * @test
+	 * @author Christian Kuhn <lolli@schwarzbu.ch>
+	 */
+	public function setSavesCompressedDataWithEnabledCompression() {
+		$mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
+		$mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
+		$this->setUpBackend(
+			array(
+				'compression' => TRUE,
+			)
+		);
+		$this->backend->setCache($mockCache);
+
+		$data = 'some data ' . microtime();
+
+		$entryIdentifier = 'BackendDbTest';
+
+		$this->backend->set($entryIdentifier, $data);
+
+		$entry = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+			'content',
+			$this->testingCacheTable,
+			'identifier = \'' . $entryIdentifier . '\''
+		);
+
+		$this->assertEquals($data, @gzuncompress($entry[0]['content']), 'Original and compressed data don\'t match');
+	}
+
+	/**
+	 * @test
+	 * @author Christian Kuhn <lolli@schwarzbu.ch>
+	 */
+	public function setSavesPlaintextDataWithEnabledCompressionAndCompressionLevel0() {
+		$mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
+		$mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
+		$this->setUpBackend(
+			array(
+				'compression' => TRUE,
+				'compressionLevel' => 0,
+			)
+		);
+		$this->backend->setCache($mockCache);
+
+		$data = 'some data ' . microtime();
+
+		$entryIdentifier = 'BackendDbTest';
+
+		$this->backend->set($entryIdentifier, $data);
+
+		$entry = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+			'content',
+			$this->testingCacheTable,
+			'identifier = \'' . $entryIdentifier . '\''
+		);
+
+		$this->assertGreaterThan(0, substr_count($entry[0]['content'], $data), 'Plaintext data not found');
+	}
+
+	/**
+	 * @test
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function getReturnsContentOfTheCorrectCacheEntry() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -273,6 +360,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function hasReturnsTheCorrectResult() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -295,6 +383,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function removeReallyRemovesACacheEntry() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -332,6 +421,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function collectGarbageReallyRemovesAnExpiredCacheEntry() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -371,6 +461,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function collectGarbageReallyRemovesAllExpiredCacheEntries() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -413,6 +504,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -440,6 +532,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function flushRemovesAllCacheEntries() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -470,6 +563,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function flushByTagRemovesCacheEntriesWithSpecifiedTag() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -504,6 +598,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function hasReturnsTheCorrectResultForEntryWithExceededLifetime() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -532,6 +627,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function getReturnsFalseForEntryWithExceededLifetime() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -561,6 +657,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function findIdentifiersByTagReturnsEmptyArrayForEntryWithExceededLifetime() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -584,6 +681,7 @@
 	 * @author Ingo Renner <ingo@typo3.org>
 	 */
 	public function setWithUnlimitedLifetimeWritesCorrectEntry() {
+		$this->setUpBackend();
 		$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
 			array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
 			array(),
@@ -608,21 +706,6 @@
 		$retrievedData = $entriesFound[0]['content'];
 		$this->assertEquals($data, $retrievedData, 'The original and the retrieved data don\'t match.');
 	}
-
-
-	/**
-	 * @author Ingo Renner <ingo@typo3.org>
-	 */
-	public function tearDown() {
-		$GLOBALS['TYPO3_DB']->sql_query(
-			'DROP TABLE ' . $this->testingCacheTable . ';'
-		);
-
-		$GLOBALS['TYPO3_DB']->sql_query(
-			'DROP TABLE ' . $this->testingTagsTable . ';'
-		);
-	}
-
 }
 
 ?>
\ No newline at end of file
Index: t3lib/stddb/tables.sql
===================================================================
--- t3lib/stddb/tables.sql	(revision 8193)
+++ t3lib/stddb/tables.sql	(working copy)
@@ -140,7 +140,7 @@
   id int(11) unsigned NOT NULL auto_increment,
   identifier varchar(128) DEFAULT '' NOT NULL,
   crdate int(11) unsigned DEFAULT '0' NOT NULL,
-  content mediumtext,
+  content mediumblob,
   lifetime int(11) unsigned DEFAULT '0' NOT NULL,
   PRIMARY KEY (id),
   KEY cache_id (identifier)
Index: t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php
===================================================================
--- t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php	(revision 8193)
+++ t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php	(working copy)
@@ -36,6 +36,16 @@
 	protected $cacheTable;
 	protected $tagsTable;
 
+	/**
+	 * @var boolean Indicates wether data is compressed or not (requires php zlib)
+	 */
+	protected $compression = FALSE;
+
+	/**
+	 * @var integer -1 to 9, indicates zlib compression level: -1 = default level 6, 0 = no compression, 9 maximum compression
+	 */
+	protected $compressionLevel = -1;
+
 	protected $identifierField;
 	protected $creationField;
 	protected $lifetimeField;
@@ -116,6 +126,10 @@
 
 		$this->remove($entryIdentifier);
 
+		if ($this->compression) {
+			$data = gzcompress($data, $this->compressionLevel);
+		}
+
 		$GLOBALS['TYPO3_DB']->exec_INSERTquery(
 			$this->cacheTable,
 			array(
@@ -168,6 +182,10 @@
 			$cacheEntry = $cacheEntries[0]['content'];
 		}
 
+		if ($this->compression && strlen($cacheEntry)) {
+			$cacheEntry = gzuncompress($cacheEntry);
+		}
+
 		return $cacheEntry;
 	}
 
@@ -448,6 +466,28 @@
 	}
 
 	/**
+	 * Enable data compression
+	 *
+	 * @param boolean TRUE to enable compression
+	 */
+	public function setCompression($compression) {
+		$this->compression = $compression;
+	}
+
+	/**
+	 * Set data compression level.
+	 * If compression is enabled and this is not set,
+	 * gzcompress default level will be used
+	 *
+	 * @param integer -1 to 9: Compression level
+	 */
+	public function setCompressionLevel($compressionLevel) {
+		if ($compressionLevel >= -1 && $compressionLevel <= 9) {
+			$this->compressionLevel = $compressionLevel;
+		}
+	}
+
+	/**
 	 * 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.
 	 *
Index: typo3/sysext/cms/ext_tables.sql
===================================================================
--- typo3/sysext/cms/ext_tables.sql	(revision 8193)
+++ typo3/sysext/cms/ext_tables.sql	(working copy)
@@ -43,7 +43,7 @@
   id int(11) unsigned NOT NULL auto_increment,
   identifier varchar(128) DEFAULT '' NOT NULL,
   crdate int(11) unsigned DEFAULT '0' NOT NULL,
-  content mediumtext,
+  content mediumblob,
   lifetime int(11) unsigned DEFAULT '0' NOT NULL,
   PRIMARY KEY (id),
   KEY cache_id (identifier)
@@ -70,7 +70,7 @@
   id int(11) unsigned NOT NULL auto_increment,
   identifier varchar(128) DEFAULT '' NOT NULL,
   crdate int(11) unsigned DEFAULT '0' NOT NULL,
-  content mediumtext,
+  content mediumblob,
   lifetime int(11) unsigned DEFAULT '0' NOT NULL,
   PRIMARY KEY (id),
   KEY cache_id (identifier)
