8000 merged branch KingCrunch/feature/static-template-cache (PR #6083) · sun/symfony@ee346bb · GitHub
[go: up one dir, main page]

Skip to content

Commit ee346bb

Browse files
committed
merged branch KingCrunch/feature/static-template-cache (PR symfony#6083)
This PR was squashed before being merged into the master branch (closes symfony#6083). Commits ------- 6236c18 [FrameworkBundle] Added caching to TemplateController Discussion ---------- [FrameworkBundle] Added caching to TemplateController Because the main purpose for the `TemplateController` seems to be to render static pages like "disclaimer" and such, it seems useful to allow caching. imprint: pattern: /imprint defaults: _controller: SymfonyFrameworkBundle:Template:template template: "::pages/imprint.html.twig" maxAge: 86400 --------------------------------------------------------------------------- by pierredup at 2012-11-21T20:24:53Z IMHO I think the caching should be allowed to be set optionally --------------------------------------------------------------------------- by KingCrunch at 2012-11-21T20:38:54Z I wrote it this way, because I assume, that it will cover more use-cases, than the other way round, but you are right, that this will change the current behaviour. Would like to hear other opinions, because I don't think one uses this action for anything else than fully-static content (means: The current behaviour doesn't feel very useful to me). --------------------------------------------------------------------------- by pierredup at 2012-11-21T20:48:19Z I totally agree, but I would then suggest keep the caching on by default, but have the option to turn it off if necessary --------------------------------------------------------------------------- by pierredup at 2012-11-21T20:52:01Z Actually I think to have caching permanently enabled for static content would probably be the best scenario, but I like to think in terms of flexibility and specific user requirements. It would be great to get some opinions from others on this --------------------------------------------------------------------------- by KingCrunch at 2012-11-23T21:12:45Z I thought about it and I come to the conclusion, that it is probably a not so good idea to enable caching by default, because ... well, it's not possible to disable it again. I guess something like this {{ render '@AcmeBundle:ArticleController:latest' with {count: 1} }} may be not so uncommon as I suggested in the first commit. --------------------------------------------------------------------------- by fabpot at 2012-12-03T22:18:51Z Can you make a PR for the docs? (symfony/symfony-docs). Thanks.
2 parents e75c7e2 + 6236c18 commit ee346bb

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,28 @@ class TemplateController extends ContainerAware
2525
* Renders a template.
2626
*
2727
* @param string $template The template name
28+
* @param int|null $maxAge Max age for client caching
29+
* @param int|null $sharedAge Max age for shared (proxy) caching
30+
* @param Boolean|null $private Whether or not caching should apply for client caches only
2831
*
2932
* @return Response A Response instance
3033
*/
31-
public function templateAction($template)
34+
public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null)
3235
{
33-
return $this->container->get('templating')->renderResponse($template);
36+
/** @var $response \Symfony\Component\HttpFoundation\Response */
37+
$response = $this->container->get('templating')->renderResponse($template);
38+
if ($maxAge) {
39+
$response->setMaxAge($maxAge);
40+
}
41+
if ($sharedAge) {
42+
$response->setSharedMaxAge($sharedAge);
43+
}
44+
45+
if ($private) {
46+
$response->setPrivate();
47+
} else if ($private === false || (is_null($private) && ($maxAge || $sharedAge))) {
48+
$response->setPublic($private);
49+
}
50+
return $response;
3451
}
3552
}

0 commit comments

Comments
 (0)
0