Symfony caching question (caching a partial)
I am using Symfony 1.3.2 and I have a page that uses a partial from another module.
I have two modules: 'foo' and 'foobar'. In module 'foo', I have an 'index' action, which uses a 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 '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 apps/frontend/modules/foo/config/cache.yml
I need to know how to cache 'part2' of the page (i.e. the [very expensive] partial part of the page. can anyone te开发者_如何学Goll me what entries are required in the cache.yml file?
If you want to cache the partial named 'part2' of the 'foobar' module, 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 from your index action in foo, a cached version (if available) will be shown:
<?php include_partial('foobar/part2') ?>
If you want to cache a different version of the partial for each template that calls it, you should edit the cache.yml file like this:
_part2:
enabled: on
lifetime: 600 # 10 minutes
contextual: true
精彩评论