Changeset 7617
- Timestamp:
- 02/26/08 23:23:55 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/routing/sfPatternRouting.class.php
r7616 r7617 26 26 $currentRouteParameters = null, 27 27 $defaultSuffix = '', 28 $routes = array(); 28 $routes = array(), 29 $cacheData = array(), 30 $cacheChanged = false; 29 31 30 32 /** … … 64 66 65 67 $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 } 66 73 } 67 74 … … 71 78 public function loadConfiguration() 72 79 { 73 if ( $routes = $this->cache->get('configuration'))80 if (!is_null($this->cache) && $routes = $this->cache->get('configuration')) 74 81 { 75 82 $this->routes = unserialize($routes); … … 84 91 parent::loadConfiguration(); 85 92 86 $this->cache->set('configuration', serialize($this->routes)); 93 if (!is_null($this->cache)) 94 { 95 $this->cache->set('configuration', serialize($this->routes)); 96 } 87 97 } 88 98 } … … 418 428 $params = $this->fixDefaults($params); 419 429 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 420 439 // named route? 421 440 if ($name) … … 521 540 } 522 541 542 if (!is_null($this->cache)) 543 { 544 $this->cacheChanged = true; 545 $this->cacheData[$cacheKey] = $realUrl; 546 } 547 523 548 return $realUrl; 524 549 } … … 543 568 // remove multiple / 544 569 $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 } 545 579 546 580 $found = false; … … 594 628 } 595 629 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; 597 639 } 598 640 … … 608 650 return $parameters; 609 651 } 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 } 610 664 }

