Symfony caching issue (partial caching)

I am using Symfony 1.3.2, and I have a page that uses partial from another module.

I have two modules: 'foo' and 'foobar'. In the "foo" module, I have an "index" action that uses the partial from the "foobar" module.

so foo / indexSuccess.php looks something like this:

<?php <div id = 'container'> <div id='part1'>Some data here</div> <div id='part2'><?php include_partial('foobar/foobar_partial', $partial_params); ?></div> </div> ?> 

I want to cache the 'part2' of my foo / indexSuccess.php page because it is very expensive (slow). I want the cache to have a lifetime of about 10 minutes.

In /frontend/modules/foo/config/cache.yml applications

I need to know how to cache the "part2" of the page (ie the [very expensive] partial part of the page. Can someone tell me which entries are required in the cache.yml file?

+4
source share
1 answer

If you want to cache the part called "part2" of the module "foobar", you need to add these lines to the file apps / frontend / modules / foobar / config / cache.yml

 _part2: enabled: on lifetime: 600 # 10 minutes 

When you then call the partial of your index action in foo, the cached version will be shown (if available):

 <?php include_partial('foobar/part2') ?> 

If you want to cache a different partial version for each template that calls it, you must edit the cache.yml file as follows:

 _part2: enabled: on lifetime: 600 # 10 minutes contextual: true 
+5
source

Source: https://habr.com/ru/post/1307267/


All Articles