Skip to content

Commit

Permalink
feature #271 Enable ESI caching for blog index (Sergiu Popa, sergiu-p…
Browse files Browse the repository at this point in the history
…opa)

This PR was merged into the master branch.

Discussion
----------

Enable ESI caching for blog index

We could update the demo app to include by default ESI caching for the blog index and the sidebar.

Commits
-------

dd93ac4 Add current locale in render_esi
0fe72d0 Move Cache Annotation up
536896a Fix base.html.twig to include about
2fc22a9 Rename sidebar to about
54b8733 Change set shared max age with annotation
4d55e53 Remove fragments from config.yml
c4b3816 Remove sidebar action and call Template Controller
e1868eb New line at the end
93d9254 Replace config.php current
09b055f Remove time and add config comments
5d93dea Enable ESI caching for blog index
  • Loading branch information
javiereguiluz committed Dec 16, 2015
2 parents e064efe + dd93ac4 commit 895c518
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
17 changes: 6 additions & 11 deletions app/Resources/views/base.html.twig
Expand Up @@ -35,7 +35,7 @@
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="{{ path('homepage') }}">
Symfony Demo
Symfony Demo <!-- ESI TIME: {{ "now"|date('H:i:s') }} -->
</a>

<button type="button" class="navbar-toggle"
Expand Down Expand Up @@ -105,16 +105,11 @@

<div id="sidebar" class="col-sm-3">
{% block sidebar %}
<div class="section about">
<div class="well well-lg">
<p>
{{ 'help.app_description'|trans|raw }}
</p>
<p>
{{ 'help.more_information'|trans|raw }}
</p>
</div>
</div>
{{ render_esi(controller('FrameworkBundle:Template:template', {
'template': 'blog/about.html.twig',
'sharedAge': 600,
'_locale': app.request.locale
})) }}
{% endblock %}
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions app/Resources/views/blog/about.html.twig
@@ -0,0 +1,11 @@
<div class="section about">
<div class="well well-lg">
<p>
{{ 'help.app_description'|trans|raw }}
</p>
<p>
{{ 'help.more_information'|trans|raw }}
</p>
<!-- ESI TIME: {{ "now"|date('H:i:s') }} -->
</div>
</div>
4 changes: 3 additions & 1 deletion app/config/config.yml
Expand Up @@ -26,7 +26,9 @@ framework:
# See http://symfony.com/doc/current/reference/configuration/framework.html#ide
ide: sublime

# esi: ~
# ESI enabled for blog index and sidebar
# http://symfony.com/doc/current/book/http_cache.html#edge-side-includes
esi: { enabled: true }
translator: { fallback: "%locale%" }
secret: "%secret%"
router:
Expand Down
2 changes: 2 additions & 0 deletions src/AppBundle/Controller/BlogController.php
Expand Up @@ -14,6 +14,7 @@
use AppBundle\Entity\Comment;
use AppBundle\Entity\Post;
use AppBundle\Form\CommentType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
Expand All @@ -35,6 +36,7 @@ class BlogController extends Controller
/**
* @Route("/", name="blog_index", defaults={"page" = 1})
* @Route("/page/{page}", name="blog_index_paginated", requirements={"page" : "\d+"})
* @Cache(smaxage="10")
*/
public function indexAction($page)
{
Expand Down
2 changes: 1 addition & 1 deletion web/app.php
Expand Up @@ -33,7 +33,7 @@
// If you use HTTP Cache to improve application performance, uncomment the following lines:
// See http://symfony.com/doc/current/book/http_cache.html#symfony-reverse-proxy
//
// $kernel = new AppCache($kernel);
$kernel = new AppCache($kernel);

// If you use HTTP Cache and your application relies on the _method request parameter
// to get the intended HTTP method, uncomment this line.
Expand Down

0 comments on commit 895c518

Please sign in to comment.