[TASK] Use simple file backend for core php cache
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 5 Aug 2012 16:54:15 +0000 (18:54 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 7 Aug 2012 19:52:48 +0000 (21:52 +0200)
This patch adds a new php cache to the core that is exclusivly used
by the core for php code. It uses the quicker simple file cache backend.
This backend has no tagging functionality. If an entry needs to be
dropped, the whole cache is flushed now.

Change-Id: I33c9e1dc01c6a8c6ec463cd795657833a4ea7646
Resolves: #39539
Releases: 6.0
Reviewed-on: http://review.typo3.org/13468
Reviewed-by: Philipp Gampe
Reviewed-by: Wouter Wolters
Tested-by: Philipp Gampe
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/cache/backend/class.t3lib_cache_backend_simplefilebackend.php
t3lib/class.t3lib_autoloader.php
t3lib/class.t3lib_extmgm.php
t3lib/class.t3lib_spritemanager.php
t3lib/core_autoload.php
t3lib/stddb/DefaultConfiguration.php
tests/Unit/t3lib/class.t3lib_autoloaderTest.php
tests/Unit/t3lib/class.t3lib_extmgmTest.php
typo3/classes/Bootstrap/BaseSetup.php
typo3/sysext/lang/locallang_csh_corebe.xlf

index ebbb379..18356bc 100644 (file)
@@ -279,6 +279,7 @@ class t3lib_cache_backend_SimpleFileBackend extends t3lib_cache_backend_Abstract
 
                $temporaryCacheEntryPathAndFilename = $this->cacheDirectory . uniqid() . '.temp';
                $result = file_put_contents($temporaryCacheEntryPathAndFilename, $data);
+               t3lib_div::fixPermissions($temporaryCacheEntryPathAndFilename);
                if ($result === FALSE) {
                        throw new t3lib_cache_Exception(
                                'The temporary cache file "' . $temporaryCacheEntryPathAndFilename . '" could not be written.',
index c4cf36f..6148e42 100644 (file)
@@ -136,7 +136,7 @@ class t3lib_autoloader {
         */
        protected static function loadCoreAndExtensionRegistry() {
                /** @var $phpCodeCache t3lib_cache_frontend_PhpFrontend */
-               $phpCodeCache = $GLOBALS['typo3CacheManager']->getCache('cache_phpcode');
+               $phpCodeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
 
                        // Create autoload cache file if it does not exist yet
                if ($phpCodeCache->has(self::getAutoloadCacheIdentifier())) {
@@ -280,10 +280,9 @@ class t3lib_autoloader {
                        $cachedFileContent .= LF . '\'' . $className . '\' => ' . $nullOrLocation;
                }
                $cachedFileContent .= LF . ');';
-               $GLOBALS['typo3CacheManager']->getCache('cache_phpcode')->set(
+               $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(
                        self::getAutoloadCacheIdentifier(),
-                       $cachedFileContent,
-                       array('t3lib_autoloader', 'core')
+                       $cachedFileContent
                );
        }
 
index a7343be..7b1049a 100644 (file)
@@ -1541,16 +1541,15 @@ tt_content.' . $key . $prefix . ' {
        public static function loadTypo3LoadedExtensionInformation($allowCaching = TRUE) {
                if ($allowCaching) {
                        $cacheIdentifier = self::getTypo3LoadedExtensionInformationCacheIdentifier();
-                       /** @var $phpCodeCache t3lib_cache_frontend_PhpFrontend */
-                       $phpCodeCache = $GLOBALS['typo3CacheManager']->getCache('cache_phpcode');
-                       if ($phpCodeCache->has($cacheIdentifier)) {
-                               $typo3LoadedExtensionArray = $phpCodeCache->requireOnce($cacheIdentifier);
+                       /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
+                       $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+                       if ($codeCache->has($cacheIdentifier)) {
+                               $typo3LoadedExtensionArray = $codeCache->requireOnce($cacheIdentifier);
                        } else {
                                $typo3LoadedExtensionArray = self::createTypo3LoadedExtensionInformationArray();
-                               $phpCodeCache->set(
+                               $codeCache->set(
                                        $cacheIdentifier,
-                                       'return ' . var_export($typo3LoadedExtensionArray, TRUE) . ';',
-                                       array('typo3LoadedExtensionArray', 'core')
+                                       'return ' . var_export($typo3LoadedExtensionArray, TRUE) . ';'
                                );
                        }
                } else {
@@ -1654,10 +1653,10 @@ tt_content.' . $key . $prefix . ' {
        public static function loadExtLocalconf($allowCaching = TRUE) {
                if ($allowCaching) {
                        $cacheIdentifier = self::getExtLocalconfCacheIdentifier();
-                       /** @var $phpCodeCache t3lib_cache_frontend_PhpFrontend */
-                       $phpCodeCache = $GLOBALS['typo3CacheManager']->getCache('cache_phpcode');
-                       if ($phpCodeCache->has($cacheIdentifier)) {
-                               $phpCodeCache->requireOnce($cacheIdentifier);
+                       /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
+                       $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+                       if ($codeCache->has($cacheIdentifier)) {
+                               $codeCache->requireOnce($cacheIdentifier);
                        } else {
                                self::loadSingleExtLocalconfFiles();
                                self::createExtLocalconfCacheEntry();
@@ -1736,10 +1735,9 @@ tt_content.' . $key . $prefix . ' {
                        // Remove all start and ending php tags from content
                $phpCodeToCache = preg_replace('/<\?php|\?>/is', '', $phpCodeToCache);
 
-               $GLOBALS['typo3CacheManager']->getCache('cache_phpcode')->set(
+               $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(
                        self::getExtLocalconfCacheIdentifier(),
-                       $phpCodeToCache,
-                       array('concatenatedExtLocalconf', 'core')
+                       $phpCodeToCache
                );
        }
 
@@ -1768,10 +1766,10 @@ tt_content.' . $key . $prefix . ' {
                if ($allowCaching && !self::$extTablesWasReadFromCacheOnce) {
                        self::$extTablesWasReadFromCacheOnce = TRUE;
                        $cacheIdentifier = self::getExtTablesCacheIdentifier();
-                       /** @var $phpCodeCache t3lib_cache_frontend_PhpFrontend */
-                       $phpCodeCache = $GLOBALS['typo3CacheManager']->getCache('cache_phpcode');
-                       if ($phpCodeCache->has($cacheIdentifier)) {
-                               $phpCodeCache->requireOnce($cacheIdentifier);
+                       /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
+                       $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+                       if ($codeCache->has($cacheIdentifier)) {
+                               $codeCache->requireOnce($cacheIdentifier);
                        } else {
                                self::loadSingleExtTablesFiles();
                                self::createExtTablesCacheEntry();
@@ -1849,10 +1847,9 @@ tt_content.' . $key . $prefix . ' {
                        // Remove all start and ending php tags from content
                $phpCodeToCache = preg_replace('/<\?php|\?>/is', '', $phpCodeToCache);
 
-               $GLOBALS['typo3CacheManager']->getCache('cache_phpcode')->set(
+               $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(
                        self::getExtTablesCacheIdentifier(),
-                       $phpCodeToCache,
-                       array('combinedExtTables', 'core')
+                       $phpCodeToCache
                );
        }
 
@@ -1987,9 +1984,9 @@ tt_content.' . $key . $prefix . ' {
         * @return void
         */
        public static function removeCacheFiles() {
-               /** @var $phpCodeCache t3lib_cache_frontend_PhpFrontend */
-               $phpCodeCache = $GLOBALS['typo3CacheManager']->getCache('cache_phpcode');
-               $phpCodeCache->flushByTag('core');
+               /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
+               $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+               $codeCache->flush();
        }
 
        /**
@@ -2285,4 +2282,4 @@ tt_content.' . $key . $prefix . ' {
        }
 }
 
-?>
\ No newline at end of file
+?>
index ec44a06..f6ae6d6 100644 (file)
@@ -53,13 +53,13 @@ class t3lib_SpriteManager {
         */
        public static function initialize() {
                $cacheIdentifier = static::getCacheIdentifier();
-               /** @var $phpCodeCache t3lib_cache_frontend_PhpFrontend */
-               $phpCodeCache = $GLOBALS['typo3CacheManager']->getCache('cache_phpcode');
-               if ($phpCodeCache->has($cacheIdentifier)) {
-                       $phpCodeCache->requireOnce($cacheIdentifier);
+               /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
+               $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+               if ($codeCache->has($cacheIdentifier)) {
+                       $codeCache->requireOnce($cacheIdentifier);
                } else {
                        static::createSpriteCache();
-                       $phpCodeCache->requireOnce($cacheIdentifier);
+                       $codeCache->requireOnce($cacheIdentifier);
                }
        }
 
@@ -111,11 +111,10 @@ class t3lib_SpriteManager {
                $cacheString = addslashes(serialize($iconNames));
                $cacheFileContent = '$GLOBALS[\'TBE_STYLES\'][\'spriteIconApi\'][\'iconsAvailable\'] = unserialize(stripslashes(\'' . $cacheString . '\'));';
 
-               /** @var $phpCodeCache t3lib_cache_frontend_PhpFrontend */
-               $GLOBALS['typo3CacheManager']->getCache('cache_phpcode')->set(
+               /** @var $codeCache t3lib_cache_frontend_PhpFrontend */
+               $GLOBALS['typo3CacheManager']->getCache('cache_core')->set(
                        static::getCacheIdentifier(),
-                       $cacheFileContent,
-                       array('t3lib_cachemanager', 'core')
+                       $cacheFileContent
                );
        }
 
index 6dcab4f..f934c64 100644 (file)
@@ -23,6 +23,7 @@ $t3libClasses = array(
        't3lib_cache_backend_backend' => PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php',
        't3lib_cache_backend_dbbackend' => PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_dbbackend.php',
        't3lib_cache_backend_filebackend' => PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_filebackend.php',
+       't3lib_cache_backend_freezablebackend' => PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_freezablebackend.php',
        't3lib_cache_backend_memcachedbackend' => PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_memcachedbackend.php',
        't3lib_cache_backend_nullbackend' => PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_nullbackend.php',
        't3lib_cache_backend_pdobackend' => PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_pdobackend.php',
index d27a60d..707d7a3 100644 (file)
@@ -131,6 +131,13 @@ return array(
                'reverseProxyPrefixSSL' => '',                          // String: prefix to be added to the internal URL (SCRIPT_NAME and REQUEST_URI) when accessing the server via an SSL proxy. This setting overrides <a href="#SYS-reverseProxyPrefix">[SYS][reverseProxyPrefix]</a>.
                'caching' => array(
                        'cacheConfigurations' => array(
+                                       // The cache_core cache is is for core php code only and must
+                                       // not be abused by third party extensions.
+                               'cache_core' => array(
+                                       'frontend' => 't3lib_cache_frontend_PhpFrontend',
+                                       'backend' => 't3lib_cache_backend_SimpleFileBackend',
+                                       'options' => array(),
+                               ),
                                'cache_hash' => array(
                                        'frontend' => 't3lib_cache_frontend_VariableFrontend',
                                        'backend' => 't3lib_cache_backend_DbBackend',
index d637adc..afe3a82 100644 (file)
@@ -121,12 +121,12 @@ class t3lib_autoloaderTest extends Tx_Phpunit_TestCase {
        /**
         * @test
         */
-       public function unregisterAutoloaderSetsCacheEntryWithT3libAutoloaderAndCoreTag() {
+       public function unregisterAutoloaderSetsCacheEntryWithT3libNoTags() {
                $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
                        // Expect the mock cache set method to be called
                        // once with t3lib_autoloader as third parameter
                $mockCache->expects($this->once())->method('set')
-                       ->with($this->anything(), $this->anything(), array('t3lib_autoloader', 'core'));
+                       ->with($this->anything(), $this->anything(), array());
                $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager', array('getCache'));
                $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
                t3lib_autoloader::unregisterAutoloader();
index 1262288..5f20d82 100644 (file)
@@ -784,13 +784,13 @@ class t3lib_extmgmTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function loadTypo3LoadedExtensionInformationSetsNewCacheEntryTaggedWithTypo3LoadedExtensionArrayAndCore() {
+       public function loadTypo3LoadedExtensionInformationSetsNewCacheEntryWithNoTags() {
                $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
                $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager', array('getCache'));
                $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
                $mockCache->expects($this->any())->method('has')->will($this->returnValue(FALSE));
                $mockCache->expects($this->once())->method('set')
-                       ->with($this->anything(), $this->anything(), $this->equalTo(array('typo3LoadedExtensionArray', 'core')));
+                       ->with($this->anything(), $this->anything(), $this->equalTo(array()));
                t3lib_extMgm::loadTypo3LoadedExtensionInformation(TRUE);
        }
 
@@ -918,12 +918,12 @@ class t3lib_extmgmTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function createExtLocalconfCacheEntryWritesCacheEntryTaggedWithCore() {
+       public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags() {
                $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
                $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager', array('getCache'));
                $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
                $mockCache->expects($this->once())->method('set')
-                       ->with($this->anything(), $this->anything(), $this->equalTo(array('concatenatedExtLocalconf', 'core')));
+                       ->with($this->anything(), $this->anything(), $this->equalTo(array()));
                t3lib_extMgmAccessibleProxy::createExtLocalconfCacheEntry();
        }
 
@@ -1002,12 +1002,12 @@ class t3lib_extmgmTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function createExtTablesCacheEntryWritesCacheEntryTaggedWithCore() {
+       public function createExtTablesCacheEntryWritesCacheEntryWithNoTags() {
                $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
                $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager', array('getCache'));
                $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
                $mockCache->expects($this->once())->method('set')
-                       ->with($this->anything(), $this->anything(), $this->equalTo(array('combinedExtTables', 'core')));
+                       ->with($this->anything(), $this->anything(), $this->equalTo(array()));
                t3lib_extMgmAccessibleProxy::createExtTablesCacheEntry();
        }
 
@@ -1033,11 +1033,11 @@ class t3lib_extmgmTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function removeCacheFilesRemovesCacheEntriesTaggedWithCore() {
+       public function removeCacheFilesFlushesCache() {
                $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
                $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager', array('getCache'));
                $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
-               $mockCache->expects($this->once())->method('flushByTag')->with($this->equalTo('core'));
+               $mockCache->expects($this->once())->method('flush');
                t3lib_extMgm::removeCacheFiles();
        }
 
index 2190559..c0fe5e1 100644 (file)
@@ -222,12 +222,10 @@ class Typo3_Bootstrap_BaseSetup {
                require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_stringfrontend.php');
                require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_phpfrontend.php');
                require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php');
+               require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_taggablebackend.php');
                require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php');
                require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_phpcapablebackend.php');
-               require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_freezablebackend.php');
-               require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_taggablebackend.php');
                require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_simplefilebackend.php');
-               require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_filebackend.php');
                require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_nullbackend.php');
 
                require_once(PATH_t3lib . 'class.t3lib_autoloader.php');
@@ -535,4 +533,4 @@ class Typo3_Bootstrap_BaseSetup {
                return $directory . '/';
        }
 }
-?>
\ No newline at end of file
+?>
index dd66ff6..276943f 100644 (file)
@@ -64,7 +64,7 @@ For another backend user it might be different. This screen shot shows how anoth
 A very central cache is the database cache table, "cache_hash", which needs to be flushed after certain major changes in the system. You "clear all cache" by clicking the link with the blue icon. After this operation any website content should be re-generated from the sources rather than be delivered from caches. This operation clears &lt;i&gt;all&lt;/i&gt; database tables registered as flushable cache tables.
 
 &lt;b&gt;Cached PHP configuration files from Extensions&lt;/b&gt;
-TYPO3 also caches small configuration scripts from extensions, "ext_localconf.php" and "ext_tables.php". These files are simply read from all installed extensions and concatenated into temporary PHP scripts found in the typo3temp/Cache/Code/cache_phpcode/ folder. Sometimes you need to remove these files so TYPO3 re-writes them from the originals. This is done by the "Clear temp_CACHED" link.
+TYPO3 also caches small configuration scripts from extensions, "ext_localconf.php" and "ext_tables.php". These files are simply read from all installed extensions and concatenated into temporary PHP scripts found in the typo3temp/Cache/Code/cache_core/ folder. Sometimes you need to remove these files so TYPO3 re-writes them from the originals. This is done by the "Clear temp_CACHED" link.
 
 &lt;b&gt;Notice:&lt;/b&gt; You should not clear these caches without a second thought. Clearing caches may affect performance on your server negatively for a while. Obviously the cached content has to be regenerated which takes time and under heavy load it might make your server un-available for a while.</source>
                        </trans-unit>