Development

Changeset 7617

You must first sign up to be able to contribute.

Changeset 7617

Show
Ignore:
Timestamp:
02/26/08 23:23:55 (1 year ago)
Author:
fabien
Message:

added routing cache for generate() and parse() method (massive speedup!)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/routing/sfPatternRouting.class.php

    r7616 r7617  
    2626    $currentRouteParameters = null, 
    2727    $defaultSuffix          = '', 
    28     $routes                 = array(); 
     28    $routes                 = array(), 
     29    $cacheData              = array(), 
     30    $cacheChanged           = false; 
    2931 
    3032  /** 
     
    6466 
    6567    $this->setDefaultSuffix(isset($options['suffix']) ? $options['suffix'] : ''); 
     68 
     69    if (!is_null($this->cache) && $cacheData = $this->cache->get('data')) 
     70    { 
     71      $this->cacheData = unserialize($cacheData); 
     72    } 
    6673  } 
    6774 
     
    7178  public function loadConfiguration() 
    7279  { 
    73     if ($routes = $this->cache->get('configuration')) 
     80    if (!is_null($this->cache) && $routes = $this->cache->get('configuration')) 
    7481    { 
    7582      $this->routes = unserialize($routes); 
     
    8491      parent::loadConfiguration(); 
    8592 
    86       $this->cache->set('configuration', serialize($this->routes)); 
     93      if (!is_null($this->cache)) 
     94      { 
     95        $this->cache->set('configuration', serialize($this->routes)); 
     96      } 
    8797    } 
    8898  } 
     
    418428    $params = $this->fixDefaults($params); 
    419429 
     430    if (!is_null($this->cache)) 
     431    { 
     432      $cacheKey = 'generate_'.$name.serialize($params); 
     433      if (isset($this->cacheData[$cacheKey])) 
     434      { 
     435        return $this->cacheData[$cacheKey]; 
     436      } 
     437    } 
     438 
    420439    // named route? 
    421440    if ($name) 
     
    521540    } 
    522541 
     542    if (!is_null($this->cache)) 
     543    { 
     544      $this->cacheChanged = true; 
     545      $this->cacheData[$cacheKey] = $realUrl; 
     546    } 
     547 
    523548    return $realUrl; 
    524549  } 
     
    543568    // remove multiple / 
    544569    $url = preg_replace('#/+#', '/', $url); 
     570 
     571    if (!is_null($this->cache)) 
     572    { 
     573      $cacheKey = 'parse_'.$url; 
     574      if (isset($this->cacheData[$cacheKey])) 
     575      { 
     576        return $this->cacheData[$cacheKey]; 
     577      } 
     578    } 
    545579 
    546580    $found = false; 
     
    594628    } 
    595629 
    596     return $this->currentRouteParameters = $this->fixDefaults($out); 
     630    $this->currentRouteParameters = $this->fixDefaults($out); 
     631 
     632    if (!is_null($this->cache)) 
     633    { 
     634      $this->cacheChanged = true; 
     635      $this->cacheData[$cacheKey] = $this->currentRouteParameters; 
     636    } 
     637 
     638    return $this->currentRouteParameters; 
    597639  } 
    598640 
     
    608650    return $parameters; 
    609651  } 
     652 
     653  /** 
     654   * @see sfRouting 
     655   */ 
     656  public function shutdown() 
     657  { 
     658    if (!is_null($this->cache) && $this->cacheChanged) 
     659    { 
     660      $this->cacheChanged = false; 
     661      $this->cache->set('data', serialize($this->cacheData)); 
     662    } 
     663  } 
    610664} 

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.