Skip to content

Commit

Permalink
Merge pull request #111 from apfelbox/route-cache-only
Browse files Browse the repository at this point in the history
Only cache routes in the Config Cache
  • Loading branch information
stof committed Dec 16, 2013
2 parents 408af3a + 7d763cd commit 71420d0
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,23 @@ public function indexAction(Request $request, $_format)
$cache = new ConfigCache($this->exposedRoutesExtractor->getCachePath($request->getLocale()), $this->debug);

if (!$cache->isFresh()) {
$content = $this->serializer->serialize(
new RoutesResponse(
$this->exposedRoutesExtractor->getBaseUrl(),
$this->exposedRoutesExtractor->getRoutes(),
$this->exposedRoutesExtractor->getPrefix($request->getLocale()),
$this->exposedRoutesExtractor->getHost(),
$this->exposedRoutesExtractor->getScheme()
),
'json'
);
$cache->write($content, $this->exposedRoutesExtractor->getResources());
$exposedRoutes = $this->exposedRoutesExtractor->getRoutes();
$serializedRoutes = $this->serializer->serialize($exposedRoutes, 'json');
$cache->write($serializedRoutes, $this->exposedRoutesExtractor->getResources());
} else {
$serializedRoutes = file_get_contents((string) $cache);
$exposedRoutes = json_decode($serializedRoutes, true);
}

$content = file_get_contents((string) $cache);
$routesResponse = new RoutesResponse(
$this->exposedRoutesExtractor->getBaseUrl(),
$exposedRoutes,
$this->exposedRoutesExtractor->getPrefix($request->getLocale()),
$this->exposedRoutesExtractor->getHost(),
$this->exposedRoutesExtractor->getScheme()
);

$content = $this->serializer->serialize($routesResponse, 'json');

if (null !== $callback = $request->query->get('callback')) {
$validator = new \JsonpCallbackValidator();
Expand Down

0 comments on commit 71420d0

Please sign in to comment.