Development

Changeset 7726

You must first sign up to be able to contribute.

Changeset 7726

Show
Ignore:
Timestamp:
03/03/08 15:16:01 (7 months ago)
Author:
fabien
Message:

moved partial and component cache management to sfPartialView

Files:

Legend:

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

    r7725 r7726  
    110110  $actionName = '_'.$componentName; 
    111111 
    112   // check cache 
    113   if ($cacheManager = $context->getViewCacheManager()) 
    114   { 
    115     $cacheManager->registerConfiguration($moduleName); 
    116     if ($retval = $cacheManager->getPartialCache($moduleName, $actionName, $cacheManager->computeCacheKey($vars))) 
    117     { 
    118       return $retval; 
    119     } 
    120     else 
    121     { 
    122       $mainResponse = $context->getResponse(); 
    123       $responseClass = get_class($mainResponse); 
    124       $context->setResponse($response = new $responseClass($context->getEventDispatcher(), $mainResponse->getOptions())); 
    125     } 
    126   } 
    127  
    128112  $allVars = _call_component($moduleName, $componentName, $vars); 
    129113 
     
    132116    // render 
    133117    $view = new sfPartialView($context, $moduleName, $actionName, ''); 
     118    $view->setPartialVars($vars); 
    134119    $view->getAttributeHolder()->add($allVars); 
    135120 
    136     $retval = $view->render(); 
    137  
    138     if ($cacheManager) 
    139     { 
    140       $retval = $cacheManager->setPartialCache($moduleName, $actionName, $cacheManager->computeCacheKey($vars), $retval); 
    141  
    142       $context->setResponse($mainResponse); 
    143       $mainResponse->merge($response); 
    144     } 
    145  
    146     return $retval; 
     121    return $view->render(); 
    147122  } 
    148123} 
     
    202177  $actionName = '_'.$templateName; 
    203178 
    204   if ($cacheManager = $context->getViewCacheManager()) 
    205   { 
    206     $cacheManager->registerConfiguration($moduleName); 
    207  
    208     $cacheKey = $cacheManager->computeCacheKey($vars); 
    209     if ($retval = $cacheManager->getPartialCache($moduleName, $actionName, $cacheKey)) 
    210     { 
    211       return $retval; 
    212     } 
    213     else 
    214     { 
    215       $mainResponse = $context->getResponse(); 
    216       $responseClass = get_class($mainResponse); 
    217       $context->setResponse($response = new $responseClass($context->getEventDispatcher(), $mainResponse->getOptions())); 
    218     } 
    219   } 
    220  
    221179  $view = new sfPartialView($context, $moduleName, $actionName, ''); 
    222   $view->getAttributeHolder()->add($vars); 
    223  
    224   $retval = $view->render(); 
    225  
    226   if ($cacheManager) 
    227   { 
    228     $retval = $cacheManager->setPartialCache($moduleName, $actionName, $cacheKey, $retval); 
    229     $context->setResponse($mainResponse); 
    230     $mainResponse->merge($response); 
    231   } 
    232  
    233   return $retval; 
     180  $view->setPartialVars($vars); 
     181 
     182  return $view->render(); 
    234183} 
    235184 
  • branches/1.1/lib/view/sfPartialView.class.php

    r7614 r7726  
    1919class sfPartialView extends sfPHPView 
    2020{ 
     21  protected 
     22    $partialVars = array(); 
     23 
    2124  /** 
    2225   * Executes any presentation logic for this view. 
     
    2427  public function execute() 
    2528  { 
     29  } 
     30 
     31  public function setPartialVars(array $partialVars) 
     32  { 
     33    $this->partialVars = $partialVars; 
    2634  } 
    2735 
     
    5664    } 
    5765 
     66    if ($cacheManager = $this->context->getViewCacheManager()) 
     67    { 
     68      $cacheManager->registerConfiguration($this->moduleName); 
     69 
     70      $cacheKey = $cacheManager->computeCacheKey($this->partialVars); 
     71      if ($retval = $cacheManager->getPartialCache($this->moduleName, $this->actionName, $cacheKey)) 
     72      { 
     73        return $retval; 
     74      } 
     75      else 
     76      { 
     77        $mainResponse = $this->context->getResponse(); 
     78        $responseClass = get_class($mainResponse); 
     79        $this->context->setResponse($response = new $responseClass($this->context->getEventDispatcher(), $mainResponse->getOptions())); 
     80      } 
     81    } 
     82 
     83    $this->getAttributeHolder()->add($this->partialVars); 
     84 
    5885    // execute pre-render check 
    5986    $this->preRenderCheck(); 
     
    6188    // render template 
    6289    $retval = $this->renderFile($this->getDirectory().'/'.$this->getTemplate()); 
     90 
     91    if ($cacheManager) 
     92    { 
     93      $retval = $cacheManager->setPartialCache($this->moduleName, $this->actionName, $cacheKey, $retval); 
     94      $this->context->setResponse($mainResponse); 
     95      $mainResponse->merge($response); 
     96    } 
    6397 
    6498    if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))