Changeset 32699
- Timestamp:
- 07/01/11 08:58:02 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.4/lib/view/sfViewCacheManager.class.php
r32698 r32699 130 130 } 131 131 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) 134 133 { 135 134 throw new sfException('A cache key cannot be generated for an internal URI using the @rule syntax'); … … 167 166 { 168 167 $cacheKey = 'sf_cache_partial/'; 169 $cacheKey .= $this->convertParametersToKey($params);170 168 } 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); 180 171 } 181 172 … … 304 295 305 296 /** 306 * Transforms an associative array of parameters from an URI into a unique key307 * This method is only used for fragment308 *309 * @param array $params Associative array of parameters from the URI (including, at least, module and action)310 *311 * @return string Unique key312 */313 protected function convertParametersToFragmentKey($params)314 {315 // module should be __sf_cache_fragment and action should be the316 // fragment name, also used as sf_cache_key parameter317 // these parameters can be removed from the generated kay318 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 /**330 297 * Adds a cache to the manager. 331 298 * … … 708 675 public function start($name, $lifeTime, $clientLifeTime = null, $vary = array()) 709 676 { 677 $internalUri = $this->routing->getCurrentInternalUri(); 678 710 679 if (!$clientLifeTime) 711 680 { 712 681 $clientLifeTime = $lifeTime; 713 682 } 714 715 // fetch fragment uri716 $internalUri = $this->getFragmentUri( $name );717 683 718 684 // add cache config to cache manager 719 685 list($route_name, $params) = $this->controller->convertUrlStringToParameters($internalUri); 720 // module should be __sf_cache_fragment and action should be the name of the fragment721 686 $this->addCache($params['module'], $params['action'], array('withLayout' => false, 'lifeTime' => $lifeTime, 'clientLifeTime' => $clientLifeTime, 'vary' => $vary)); 722 687 723 688 // 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); 726 690 if ($data !== null) 727 691 { … … 744 708 * @return bool true, if success otherwise false 745 709 */ 746 public function stop( $name)710 public function stop($name) 747 711 { 748 712 $data = ob_get_clean(); 749 713 714 // save content to cache 715 $internalUri = $this->routing->getCurrentInternalUri(); 750 716 try 751 717 { 752 $this->set( $data, $this->getFragmentUri( $name ));718 $this->set($data, $internalUri.(strpos($internalUri, '?') ? '&' : '?').'_sf_cache_key='.$name); 753 719 } 754 720 catch (Exception $e) … … 757 723 758 724 return $data; 759 }760 761 /**762 * Computes a fragment internal URI.763 *764 * @param string $name The fragement name765 *766 * @return string The internal URI767 */768 public function getFragmentUri( $name )769 {770 // in fragement case, module is __sf_cache_fragment and action is the fragment name771 // module and action are required to the set() procedure and isCacheable() method772 return sprintf('@sf_cache_fragment?module=%s&action=%s&sf_cache_key=%s', '__sf_cache_fragment' , $name , $name );773 725 } 774 726