/** * Intercepts the parent url function to first look if the cache was already generated for the same params * * @param mixed $url url to generate using cakephp array syntax * @param boolean $full wheter to generate a full url or not (http scheme) * @return string * @see Helper::url() */ function url($url = null, $full = false) { if (Configure::read('UrlCache.active')) { if ($cachedUrl = UrlCacheManager::get($url, $full)) { return $cachedUrl; } } $routerUrl = h(Router::url($url, $full)); if (Configure::read('UrlCache.active')) { UrlCacheManager::set($routerUrl); } return $routerUrl; }
/** * Intercepts the parent URL function to first look if the cache was already generated for the same params * * @param mixed $url URL to generate using CakePHP array syntax * @param boolean $full whether to generate a full url or not (http scheme) * @return string * @see Helper::url() */ public function url($url = null, $full = false) { if (Configure::read('UrlCache.runtime.afterLayout')) { return parent::url($url, $full); } if (Configure::read('UrlCache.active')) { if ($cachedUrl = UrlCacheManager::get($url, $full)) { return $cachedUrl; } } $routerUrl = parent::url($url, $full); if (Configure::read('UrlCache.active')) { UrlCacheManager::set($routerUrl); } return $routerUrl; }
public function testGlobalCache() { $res = UrlCacheManager::get(array('controller' => 'posts', 'action' => 'index'), false); $this->assertEquals(false, $res); $url = $this->HtmlHelper->url(array('controller' => 'posts', 'action' => 'index')); $this->HtmlHelper->afterLayout('foo'); # on second page the same url will not trigger a miss but a hit $this->HtmlHelper->beforeRender('foo'); $res = UrlCacheManager::get(array('controller' => 'posts', 'action' => 'index'), false); $this->assertEquals($url, $res); $this->HtmlHelper->afterLayout('foo'); }
/** * Intercepts the parent url function to first look if the cache was already generated for the same params * * @param mixed $url url to generate using cakephp array syntax * @param bool|array $full whether to generate a full url or not (http scheme). As array: full, escape. * @return string * @see Helper::url() */ public function url($url = null, $full = false) { if (is_array($full)) { $escape = isset($full['ecape']) ? $full['escape'] : true; $full = isset($full['full']) ? $full['full'] : false; } else { $escape = true; } if (Configure::read('UrlCache.active')) { if ($cachedUrl = UrlCacheManager::get($url, $full)) { return $cachedUrl; } } if (!$escape) { $routerUrl = Router::url($url, $full); } else { $routerUrl = parent::url($url, $full); } if (Configure::read('UrlCache.active')) { UrlCacheManager::set($routerUrl); } return $routerUrl; }