I'm using memcahe
for Symfony Doctrine cache drivers as below:
doctrine:
orm:
metadata_cache_driver: memcache
result_cache_driver: memcache
query_cache_driver: memcache
I have Article
and Tag
entities which are manyToMany
relationship. I have a controller which fetches all articles (with pagination) and renders them to twig. The below code is in Article
repository that uses useQueryCache()
and useResultCache()
:
$articles = $this->createQueryBuilder('a')
->orderBy('a.created_at', 'DESC')
->getQuery()
->useQueryCache(true)
->useResultCache(true)
->getResult();
That DQL is perfectly cached for query and result as I did not see the query executed in Symfony Profiler Doctrine section. The problem is the result of the associated entity Tag
not being cached. I have the following code in twig:
{% for article in articles %}
// ...
{% if article.tags|length %}
<div class="tag-wrapper clearfix">
{% for tag in article.tags %}
// ...
{% endfor %}
</div>
{% endif %}
// ...
{% endfor %}
The call article.tags
seems fetching the tags of the related article all the time without caching. I see all queries are executing on every page load in the Symfony Profiler Doctrine section. Is it possible to cache this?