From 6236c1835c289be4f1966cb8bee77cacfff17c22 Mon Sep 17 00:00:00 2001 From: Sebastian Krebs Date: Wed, 21 Nov 2012 21:00:39 +0100 Subject: [PATCH] [FrameworkBundle] Added caching to TemplateController --- .../Controller/TemplateController.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php index fd6f1aaf78..4357e76ad4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php @@ -25,11 +25,28 @@ class TemplateController extends ContainerAware * Renders a template. * * @param string $template The template name + * @param int|null $maxAge Max age for client caching + * @param int|null $sharedAge Max age for shared (proxy) caching + * @param Boolean|null $private Whether or not caching should apply for client caches only * * @return Response A Response instance */ - public function templateAction($template) + public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null) { - return $this->container->get('templating')->renderResponse($template); + /** @var $response \Symfony\Component\HttpFoundation\Response */ + $response = $this->container->get('templating')->renderResponse($template); + if ($maxAge) { + $response->setMaxAge($maxAge); + } + if ($sharedAge) { + $response->setSharedMaxAge($sharedAge); + } + + if ($private) { + $response->setPrivate(); + } else if ($private === false || (is_null($private) && ($maxAge || $sharedAge))) { + $response->setPublic($private); + } + return $response; } }