merged branch Tobion/generator-cache (PR #3892)

Commits
-------

03d30fd [Routing] remove duplicated cache of compiled routes

Discussion
----------

[Routing] remove duplicated cache of compiled routes

The UrlGenerator caches compiled routes for generating URLs. But the Route class caches it's compiled route itself as long as it does not get modified. So compiled routes are cached twice which makes no sense in my opinion.

Test pass: yes
BC break: no
This commit is contained in:
Fabien Potencier 2012-04-12 06:57:29 +02:00
commit bf1131cc50

View File

@ -19,7 +19,7 @@ use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
/**
* UrlGenerator generates URL based on a set of routes.
* UrlGenerator generates a URL based on a set of routes.
*
* @author Fabien Potencier <fabien@symfony.com>
*
@ -34,7 +34,6 @@ class UrlGenerator implements UrlGeneratorInterface
);
protected $routes;
protected $cache;
/**
* Constructor.
@ -48,7 +47,6 @@ class UrlGenerator implements UrlGeneratorInterface
{
$this->routes = $routes;
$this->context = $context;
$this->cache = array();
}
/**
@ -84,11 +82,10 @@ class UrlGenerator implements UrlGeneratorInterface
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
if (!isset($this->cache[$name])) {
$this->cache[$name] = $route->compile();
}
// the Route has a cache of its own and is not recompiled as long as it does not get modified
$compiledRoute = $route->compile();
return $this->doGenerate($this->cache[$name]->getVariables(), $route->getDefaults(), $route->getRequirements(), $this->cache[$name]->getTokens(), $parameters, $name, $absolute);
return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $absolute);
}
/**