Changeset 1467

Show
Ignore:
Timestamp:
03/15/10 04:55:38 (5 months ago)
Author:
arnoschn
Message:

adding modification time to page caching, so in an environment with multiple app-servers the cache can be validated based on timestamps

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/AkActionController/AkCacheHandler.php

    r1466 r1467  
    521521    function cachePage($content, $path = null, $language = null, $gzipped=false, $sendETag = false, $orgStrlen = null) 
    522522    { 
     523        global $_ENV; 
    523524        static $ETag; 
    524525 
     
    562563        $cacheTimestamp = time(); 
    563564        $content = $this->_modifyCacheContent($content,$addHeaders, $removeHeaders,$cacheIds,$cacheGroup); 
    564         $filename = $this->_storePageCache($content,$cacheId,$cacheGroup); 
    565         $res = $this->_cache_store->save($filename,$cacheId,$cacheGroup); 
     565        //Ak::getLogger('caching')->message('Got timestamp from ENV:'.$_ENV['_page_cache_timestamp']); 
     566        $cached_params = $this->_storePageCache($content,$cacheId,$cacheGroup,!empty($_ENV['_page_cache_timestamp'])?$_ENV['_page_cache_timestamp']:null); 
     567        $res = $this->_cache_store->save($cached_params,$cacheId,$cacheGroup); 
    566568        if ($notNormalizedCacheId != $cacheId) { 
    567569            // Store the not normalized cacheid 
    568             $filename = $this->_storePageCache($content,$cacheId,$cacheGroup); 
    569             $this->_cache_store->save($filename,$notNormalizedCacheId,$cacheGroup); 
     570            $cached_params = $this->_storePageCache($content,$cacheId,$cacheGroup); 
     571            $this->_cache_store->save($cached_params,$notNormalizedCacheId,$cacheGroup); 
    570572        } 
    571573        return $res; 
    572574 
    573575    } 
    574     function _storePageCache($content, $cacheId,$cacheGroup
     576    function _storePageCache($content, $cacheId,$cacheGroup, $timestamp = null
    575577    { 
    576578        $filename = AK_TMP_DIR.DS.'cache'.DS.$cacheGroup.DS.$cacheId.'.php'; 
     
    584586        } 
    585587        file_put_contents($filename, $content); 
    586  
    587         return $filename; 
     588        if($timestamp == null) { 
     589            $timestamp=time(); 
     590        } 
     591        touch($filename,$timestamp); 
     592        return array($filename,$timestamp); 
    588593    } 
    589594    function _stripCacheSkipSections($content) 
     
    959964    function &getCachedPage($path = null,$forcedLanguage = null) 
    960965    { 
     966        global $_ENV; 
    961967        $false = false; 
    962968        if (!$this->_cachingAllowed()) { 
     
    974980            } 
    975981            $cacheGroup = $this->_buildCacheGroup(); 
    976             $cache = $this->_cache_store->get($cacheId, $cacheGroup); 
    977  
    978             if (file_exists($cache)) { 
     982            $cached_params = $this->_cache_store->get($cacheId, $cacheGroup); 
     983            $timestamp=false; 
     984            if(is_array($cached_params)) { 
     985                $cache = $cached_params[0]; 
     986                $timestamp = $cached_params[1]; 
     987            } else { 
     988                $cache = $cached_params; 
     989            } 
     990            //Ak::getLogger('caching')->message(var_export($cached_params,true).'mtime:'.filemtime($cache)); 
     991            if (file_exists($cache) && ($timestamp!==false && filemtime($cache)==$timestamp)) { 
    979992                if(!empty($_SESSION)) { 
    980993                    /** 
     
    985998                return $cache; 
    986999            } else { 
    987  
     1000                if($timestamp!==false) { 
     1001                    /** 
     1002                     * storing timestamp for later cache saving 
     1003                     */ 
     1004                    $_ENV['_page_cache_timestamp'] = $timestamp; 
     1005                } 
    9881006                return $false; 
    9891007            }