Skip to content

Instantly share code, notes, and snippets.

@ichikaway
Created August 9, 2012 01:58
Show Gist options
  • Save ichikaway/3300279 to your computer and use it in GitHub Desktop.
Save ichikaway/3300279 to your computer and use it in GitHub Desktop.

Revisions

  1. ichikaway revised this gist Aug 9, 2012. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions gistfile1.diff
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,6 @@ index cb28f6e..c6a38c3 100644

    $url += array('controller' => $params['controller'], 'plugin' => $params['plugin']);

    - $match = false;
    + $cacheKey = 'Router-' . sha1(serialize($url));
    + $cacheConf = Cache::settings('_cake_route_');
    + if( empty($cacheConf) || ($output = Cache::read($cacheKey, '_cake_route_') ) === false ){
    - $match = false;
    + $cacheKey = 'Router-' . sha1(serialize($url));
    - $match = false;
    + $cacheKey = 'Router-' . sha1(serialize($url));
    + $cacheConf = Cache::settings('_cake_route_');
  2. ichikaway created this gist Aug 9, 2012.
    51 changes: 51 additions & 0 deletions gistfile1.diff
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php
    index cb28f6e..c6a38c3 100644
    --- a/lib/Cake/Routing/Router.php
    +++ b/lib/Cake/Routing/Router.php
    @@ -810,23 +810,30 @@ class Router {

    $url += array('controller' => $params['controller'], 'plugin' => $params['plugin']);

    - $match = false;
    + $cacheKey = 'Router-' . sha1(serialize($url));
    + $cacheConf = Cache::settings('_cake_route_');
    + if( empty($cacheConf) || ($output = Cache::read($cacheKey, '_cake_route_') ) === false ){
    - $match = false;
    + $cacheKey = 'Router-' . sha1(serialize($url));
    - $match = false;
    + $cacheKey = 'Router-' . sha1(serialize($url));
    + $cacheConf = Cache::settings('_cake_route_');
    + if( empty($cacheConf) || ($output = Cache::read($cacheKey, '_cake_route_') ) === false ){
    + $match = false;

    - for ($i = 0, $len = count(self::$routes); $i < $len; $i++) {
    - $originalUrl = $url;
    + for ($i = 0, $len = count(self::$routes); $i < $len; $i++) {
    + $originalUrl = $url;

    - if (isset(self::$routes[$i]->options['persist'], $params)) {
    - $url = self::$routes[$i]->persistParams($url, $params);
    - }
    + if (isset(self::$routes[$i]->options['persist'], $params)) {
    + $url = self::$routes[$i]->persistParams($url, $params);
    + }

    - if ($match = self::$routes[$i]->match($url)) {
    - $output = trim($match, '/');
    - break;
    + if ($match = self::$routes[$i]->match($url)) {
    + $output = trim($match, '/');
    + break;
    + }
    + $url = $originalUrl;
    + }
    + if ($match === false) {
    + $output = self::_handleNoRoute($url);
    + }
    + if(!empty($cacheConf)) {
    + Cache::write($cacheKey , $output, '_cake_route_');
    }
    - $url = $originalUrl;
    - }
    - if ($match === false) {
    - $output = self::_handleNoRoute($url);