Development

Changeset 7717

You must first sign up to be able to contribute.

Changeset 7717

Show
Ignore:
Timestamp:
03/02/08 20:28:31 (1 year ago)
Author:
fabien
Message:

moved partial/component cache management to sfViewCacheManager

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/plugins/sfCompat10Plugin/lib/helper/PartialHelper.php

    r7691 r7717  
    114114  { 
    115115    $cacheManager->registerConfiguration($moduleName); 
    116     $uri = '@sf_cache_partial?module='.$moduleName.'&action='.$actionName.'&sf_cache_key='.(isset($vars['sf_cache_key']) ? $vars['sf_cache_key'] : md5(serialize($vars))); 
    117     if ($retval = _get_cache($cacheManager, $uri)) 
     116    if ($retval = $cacheManager->getPartialCache($moduleName, $actionName, $vars)) 
    118117    { 
    119118      return $retval; 
     
    178177    if ($cacheManager) 
    179178    { 
    180       $retval = _set_cache($cacheManager, $uri, $retval); 
     179      $retval = $cacheManager->setPartialCache($moduleName, $actionName, $vars, $retval); 
    181180    } 
    182181 
     
    243242    $cacheManager->registerConfiguration($moduleName); 
    244243    $uri = '@sf_cache_partial?module='.$moduleName.'&action='.$actionName.'&sf_cache_key='.(isset($vars['sf_cache_key']) ? $vars['sf_cache_key'] : md5(serialize($vars))); 
    245     if ($retval = _get_cache($cacheManager, $uri)) 
     244    if ($retval = $cacheManager->getPartialCache($moduleName, $actionName, $vars)) 
    246245    { 
    247246      return $retval; 
     
    256255  if ($cacheManager) 
    257256  { 
    258     $retval = _set_cache($cacheManager, $uri, $retval); 
    259   } 
    260  
    261   return $retval; 
    262 
    263  
    264 function _get_cache($cacheManager, $uri) 
    265 
    266   $retval = $cacheManager->get($uri); 
    267  
    268   if (sfConfig::get('sf_web_debug')) 
    269   { 
    270     $retval = sfWebDebug::decorateContentWithDebug($uri, $retval, false); 
    271   } 
    272  
    273   return $retval; 
    274 
    275  
    276 function _set_cache($cacheManager, $uri, $retval) 
    277 
    278   $saved = $cacheManager->set($retval, $uri); 
    279  
    280   if ($saved && sfConfig::get('sf_web_debug')) 
    281   { 
    282     $retval = sfWebDebug::decorateContentWithDebug($uri, $retval, true); 
     257    $retval = $cacheManager->setPartialCache($moduleName, $actionName, $vars, $retval); 
    283258  } 
    284259 
  • branches/1.1/lib/view/sfViewCacheManager.class.php

    r7691 r7717  
    520520  } 
    521521 
     522  public function computeCacheKey($parameters) 
     523  { 
     524    return isset($parameters['sf_cache_key']) ? $parameters['sf_cache_key'] : md5(serialize($parameters)); 
     525  } 
     526 
     527  public function getPartialUri($module, $action, $parameters) 
     528  { 
     529    return sprintf('@sf_cache_partial?module=%s&action=%s&sf_cache_key=%s', $module, $action, $this->computeCacheKey($parameters)); 
     530  } 
     531 
     532  /** 
     533   * Returns whether a partial template is in the cache. 
     534   * 
     535   * @param  string  The internal URI 
     536   * 
     537   * @return Boolean true if a partial is in the cache, false otherwise 
     538   */ 
     539  public function hasPartialCache($module, $action, $parameters) 
     540  { 
     541    return $this->has($this->getPartialUri($module, $action, $parameters)); 
     542  } 
     543 
     544  /** 
     545   * Gets a partial template from the cache. 
     546   * 
     547   * @param  string The internal URI 
     548   * 
     549   * @return string The cache content 
     550   */ 
     551  public function getPartialCache($module, $action, $parameters) 
     552  { 
     553    $uri = $this->getPartialUri($module, $action, $parameters); 
     554 
     555    if (!$this->isCacheable($uri)) 
     556    { 
     557      return null; 
     558    } 
     559 
     560    // retrieve content from cache 
     561    $content = $this->get($uri); 
     562 
     563    if (is_null($content)) 
     564    { 
     565      return null; 
     566    } 
     567 
     568    if (sfConfig::get('sf_web_debug')) 
     569    { 
     570      $content = sfWebDebug::decorateContentWithDebug($uri, $content, true); 
     571    } 
     572 
     573    return $content; 
     574  } 
     575 
     576  /** 
     577   * Sets an action template in the cache. 
     578   * 
     579   * @param  string The internal URI 
     580   * @param  string The content to cache 
     581   * @param  string The view attribute holder to cache 
     582   * 
     583   * @return string The cached content 
     584   */ 
     585  public function setPartialCache($module, $action, $parameters, $content) 
     586  { 
     587    $uri = $this->getPartialUri($module, $action, $parameters); 
     588    if (!$this->isCacheable($uri)) 
     589    { 
     590      return $content; 
     591    } 
     592 
     593    $saved = $this->set($content, $uri); 
     594 
     595    if ($saved && sfConfig::get('sf_web_debug')) 
     596    { 
     597      $content = sfWebDebug::decorateContentWithDebug($uri, $content, true); 
     598    } 
     599 
     600    return $content; 
     601  } 
     602 
    522603  /** 
    523604   * Returns whether an action template is in the cache. 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.