Skip to content

Commit

Permalink
Cache sitemap.
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Feb 20, 2016
1 parent daedf3c commit ccf5361
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Controller/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ class SitemapController extends Controller
*/
public function sitemapAction()
{
return new Response($this->getSitemapGenerator()->generateSitemap(), 200, array(
$response = new Response($this->getSitemapGenerator()->generateSitemap(), 200, array(
'Content-Type' => 'text/xml',
));

return $response
->setPublic()
->setSharedMaxAge($this->getParameter('darvin_sitemap.cache_max_age'));
}

/**
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function getConfigTreeBuilder()
// more information on that topic.
$rootNode
->children()
->integerNode('cache_max_age')->min(0)->defaultValue(60 * 60)->end()
->scalarNode('template')
->cannotBeEmpty()
->defaultValue('DarvinSitemapBundle:Sitemap:sitemap.xml.twig');
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/DarvinSitemapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('darvin_sitemap.cache_max_age', $config['cache_max_age']);
$container->setParameter('darvin_sitemap.template', $config['template']);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand Down

0 comments on commit ccf5361

Please sign in to comment.