Symfony 2 Bundle for asm89/twig-cache-extension.
API: emanueleminotto.github.io/TwigCacheBundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require emanueleminotto/twig-cache-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding the following line in the app/AppKernel.php
file of your project:
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new EmanueleMinotto\TwigCacheBundle\TwigCacheBundle(),
);
}
}
# app/config/config.yml
twig_cache:
service: cache_service # instance of Doctrine\Common\Cache\Cache
The default strategy is the IndexedChainingCacheStrategy
so you can use directly this code in your Twig templates.
{# delegate to lifetime strategy #}
{% cache 'v1/summary' {time: 300} %}
{# heavy lifting template stuff here, include/render other partials etc #}
{% endcache %}
{# delegate to generational strategy #}
{% cache 'v1/summary' {gen: item} %}
{# heavy lifting template stuff here, include/render other partials etc #}
{% endcache %}
Readings:
This bundle is under the MIT license. See the complete license in the bundle:
Resources/meta/LICENSE