Caching with Twig templates #24
Replies: 1 comment
-
After some playing around I have found that the twig templates seem to require different parameters for caching, instead of passing cache="yes" and refresh="5" to cache for 5 minutes, it looks like the Twig templates actually pass the number of seconds in the cache parameter instead of yes/no (or true/false) and the refresh param is not needed {% for entry in exp.channel.entries ({channel:'news', cache:300}) %} I was also able to get Twig caching working by installing the CacheExtension as per the notes at the bottom of https://twig.symfony.com/doc/3.x/tags/cache.html |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Does anyone know how to properly cache templates / queries in Coilpack using Twig templates?
In previous versions of ExpressionEngine I had used an add-on called Stash (https://github.com/croxton/Stash) which is now deprecated and the author has recommended using Coilpack with Twig templates.
I know that the ExpressionEngine documentation has parameters for caching in native templates, which looks something like:
{exp:channel:entries channel="news" cache="yes" refresh="10"}
{title}
{/exp:channel:entries}
I am trying to find the equivalent for Twig templates, I tried:
{% for entry in exp.channel.entries ({channel:'news', cache:'yes', refresh:'10'}) %}
{{entry.title}}
{% endfor %}
but for whatever reason my Twig templates don't seem to be caching that query at all (I see no difference in the elapsed_time between page loads). I've also tried passing cache:true instead of cache:'yes' and that doesn't seem to make a difference either, I don't see anything about caching parameters on the Coilpack documentation (https://expressionengine.github.io/coilpack-docs/docs/templates/tags/channel-entries).
I also see in the Twig documentation that they added a cache feature in v3.2:
https://twig.symfony.com/doc/3.x/tags/cache.html
{% cache "cache key" ttl(300) %}
Cached for 300 seconds
{% endcache %}
but when I try this code example in the latest version of Coilpack I get an error 'Unknown "cache" tag.' So I am guessing this is not supported in Coilpack as Coilpack looks to be pulling in an older version of Twig.
Can anyone recommend a strategy for caching in Coilpack using Twig templates? Some sections of my site have some pretty heavy queries and in previous versions of ExpressionEngine I would cache a lot of those. What I would love to be able to do is something like:
{% cache "cache key" ttl(300) %}
{% set results_from_query = exp.channel.entries({ ... }) %}
{% endcache %}
Any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions