[BUGFIX] Use runtime cache in tslib_fe::get_cache_timeout
authorSteffen Gebert <steffen.gebert@typo3.org>
Sat, 4 Jun 2011 16:51:56 +0000 (18:51 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Fri, 24 Jun 2011 19:10:12 +0000 (21:10 +0200)
Thanks to #20473, start and stop times of records are now taken into
account during a page's cache lifetime calculation.
To prevent repeated computations, the value is cached inside
tslib_fe::get_cache_timeout(), using a class variable
getCacheTimeoutCache.

The Runtime Cache (#27208) not only offers a cleaner way to do so, it
also provides a remedy against the currently existing problem that
get_cache_timeout() does its job exactly twice: Once during menu
generation (which seems to work with a cloned copy of TSFE) and once
before putting the page contents into the cache. As both class instances
share the runtime cache, the second calculation can be safed.

Change-Id: I0b241749639a678ba6c1addd8d57e2256cf52bc2
Resolves: #27227
Depends: #27208
Reviewed-on: http://review.typo3.org/2531
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
typo3/sysext/cms/tslib/class.tslib_fe.php

index adc92bc..46891d6 100644 (file)
        protected $pageCache;
        protected $pageCacheTags = array();
 
-               // caches the timestamp until a cache entry for this page is valid
-       protected $getCacheTimeoutCache = NULL;
-
        /**
         * Class constructor
         * Takes a number of GET/POST input variable as arguments and stores them internally.
@@ -4537,7 +4534,12 @@ if (version == "n3") {
         * @return      integer         The cache timeout for the current page.
         */
        function get_cache_timeout() {
-               if ($this->getCacheTimeoutCache == NULL) {
+                       /** @var $runtimeCache t3lib_cache_frontend_AbstractFrontend */
+               $runtimeCache = $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
+               $cachedCacheLifetimeIdentifier = 'core-tslib_fe-get_cache_timeout';
+               $cachedCacheLifetime = $runtimeCache->get($cachedCacheLifetimeIdentifier);
+
+               if ($cachedCacheLifetime === FALSE) {
                        if ($this->page['cache_timeout']) {
                                        // Cache period was set for the page:
                                $cacheTimeout = $this->page['cache_timeout'];
@@ -4562,10 +4564,11 @@ if (version == "n3") {
                                $calculatedCacheTimeout = $this->calculatePageCacheTimeout();
                                $cacheTimeout = ($calculatedCacheTimeout < $cacheTimeout) ? $calculatedCacheTimeout : $cacheTimeout;
                        }
-                       $this->getCacheTimeoutCache = $cacheTimeout;
+                       $runtimeCache->set($cachedCacheLifetimeIdentifier, $cacheTimeout);
+                       $cachedCacheLifetime = $cacheTimeout;
                }
 
-               return $this->getCacheTimeoutCache;
+               return $cachedCacheLifetime;
        }
 
        /**
@@ -4887,4 +4890,4 @@ if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLA
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_fe.php']);
 }
 
-?>
\ No newline at end of file
+?>