9. How to Use CacheTagsBundle
● Plain cache tag
● Request attribute tag
10. How to Use CacheTagsBundle
● Plain cache tag
Add annotation @CacheTagPlain to controller
use lbarulskiCacheTagsBundleAnnotationCacheTagPlain;
/**
* @CacheTagPlain("article_name")
**/
public function articleAction(Request $request)
{
}
11. How to Use CacheTagsBundle
● Plain cache tag
Prepare response
$response = new Response('...');
$response->setPublic();
$response->setTtl(3600);
12. How to Use CacheTagsBundle
● Request attribute tag
Implements TagInterface in model
use lbarulskiCacheTagsBundleTagTagInterface;
class Article implements TagInterface
{
public function getTag()
{
return 'article_'.$this->getId();
}
}
13. How to Use CacheTagsBundle
● Plain cache tag
Add annotation @CacheTagRequestAttribute to controller
use lbarulskiCacheTagsBundleAnnotationCacheTagRequestAttribute;
/**
* @ParamConverter("article")
* @CacheTagRequestAttribute("article")
**/
public function articleAction(Article $article)
{
}
14. How to Use CacheTagsBundle
● View Template: use esi controller
{{ render_esi(controller('MainBundle:Article:article', { article:
article.id })}}
15. How to Invalidate CacheTagsBundle
● Invalidate cache tags console
$ ./app/console cache_tags:invalidate tag-name
16. How to Invalidate CacheTagsBundle
● Invalidate cache tags in controller
use lbarulskiCacheTagsBundleTagPlain;
public function updateArticleAction(Article $article)
{
$tag = 'article_name';
$this->get('cache_tags.invalidator')->invalidate(new Plain($tag));
}