Development

Changeset 32699

You must first sign up to be able to contribute.

Changeset 32699

Show
Ignore:
Timestamp:
07/01/11 08:58:02 (3 years ago)
Author:
fabien
Message:

[1.4] partially reverted previous commit

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/lib/view/sfViewCacheManager.class.php

    r32698 r32699  
    130130    } 
    131131 
    132     // note the special rules @sf_cache_partial and @sf_cache_fragment 
    133     if (strpos($internalUri, '@') === 0 && strpos($internalUri, '@sf_cache_partial') === false && strpos($internalUri, '@sf_cache_fragment') === false ) 
     132    if (strpos($internalUri, '@') === 0 && strpos($internalUri, '@sf_cache_partial') === false) 
    134133    { 
    135134      throw new sfException('A cache key cannot be generated for an internal URI using the @rule syntax'); 
     
    167166      { 
    168167        $cacheKey = 'sf_cache_partial/'; 
    169         $cacheKey .= $this->convertParametersToKey($params); 
    170168      } 
    171       elseif( $route_name == 'sf_cache_fragment' ) 
    172       { 
    173         $cacheKey = 'sf_cache_fragment/'; 
    174         $cacheKey .= $this->convertParametersToFragmentKey($params); 
    175       } 
    176       else 
    177       { 
    178         $cacheKey .= $this->convertParametersToKey($params); 
    179       } 
     169 
     170      $cacheKey .= $this->convertParametersToKey($params); 
    180171    } 
    181172 
     
    304295 
    305296  /** 
    306    * Transforms an associative array of parameters from an URI into a unique key 
    307    * This method is only used for fragment 
    308    * 
    309    * @param  array $params  Associative array of parameters from the URI (including, at least, module and action) 
    310    * 
    311    * @return string Unique key 
    312    */ 
    313   protected function convertParametersToFragmentKey($params) 
    314   { 
    315     // module should be __sf_cache_fragment and action should be the 
    316     // fragment name, also used as sf_cache_key parameter 
    317     // these parameters can be removed from the generated kay 
    318     unset($params['module'] , $params['action']); 
    319  
    320     ksort($params); 
    321     foreach ($params as $key => $value) 
    322     { 
    323       $cacheKey .= sprintf('%s/%s/', $key, $value); 
    324     } 
    325  
    326     return rtrim( $cacheKey , '/' ); 
    327   } 
    328  
    329   /** 
    330297   * Adds a cache to the manager. 
    331298   * 
     
    708675  public function start($name, $lifeTime, $clientLifeTime = null, $vary = array()) 
    709676  { 
     677    $internalUri = $this->routing->getCurrentInternalUri(); 
     678 
    710679    if (!$clientLifeTime) 
    711680    { 
    712681      $clientLifeTime = $lifeTime; 
    713682    } 
    714  
    715     // fetch fragment uri 
    716     $internalUri = $this->getFragmentUri( $name ); 
    717683 
    718684    // add cache config to cache manager 
    719685    list($route_name, $params) = $this->controller->convertUrlStringToParameters($internalUri); 
    720     // module should be __sf_cache_fragment and action should be the name of the fragment 
    721686    $this->addCache($params['module'], $params['action'], array('withLayout' => false, 'lifeTime' => $lifeTime, 'clientLifeTime' => $clientLifeTime, 'vary' => $vary)); 
    722687 
    723688    // get data from cache if available 
    724     // note that sf_cache_key is automatically add on getFragmentUri() 
    725     $data = $this->get( $internalUri ); 
     689    $data = $this->get($internalUri.(strpos($internalUri, '?') ? '&' : '?').'_sf_cache_key='.$name); 
    726690    if ($data !== null) 
    727691    { 
     
    744708   * @return bool true, if success otherwise false 
    745709   */ 
    746   public function stop( $name
     710  public function stop($name
    747711  { 
    748712    $data = ob_get_clean(); 
    749713 
     714    // save content to cache 
     715    $internalUri = $this->routing->getCurrentInternalUri(); 
    750716    try 
    751717    { 
    752       $this->set( $data, $this->getFragmentUri( $name ) ); 
     718      $this->set($data, $internalUri.(strpos($internalUri, '?') ? '&' : '?').'_sf_cache_key='.$name); 
    753719    } 
    754720    catch (Exception $e) 
     
    757723 
    758724    return $data; 
    759   } 
    760  
    761   /** 
    762    * Computes a fragment internal URI. 
    763    * 
    764    * @param  string $name      The fragement name 
    765    * 
    766    * @return string The internal URI 
    767    */ 
    768   public function getFragmentUri( $name ) 
    769   { 
    770     // in fragement case, module is __sf_cache_fragment and action is the fragment name 
    771     // module and action are required to the set() procedure and isCacheable() method 
    772     return sprintf('@sf_cache_fragment?module=%s&action=%s&sf_cache_key=%s', '__sf_cache_fragment' , $name , $name ); 
    773725  } 
    774726