Setting cache duration depending on WP_DEBUG value. #2952
Unanswered
KingWebsites
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm using the standard Timber render caching option to improve the page load speed on my site. e.g.
Timber::render('index.twig', $context, 36000);
( https://timber.github.io/docs/v2/guides/performance/ )
But because I have a number of page templates along with ACF flexible elements rendered inside these templates I'd like just one place to set the cache duration, 0 if WP_DEBUG is true, and 36000 if false. I dont want to edit templates between dev and prod.
So far I've added this code to my functions.php to set up a global PHP variable:
I use this like so in my PHP templates:
Timber::render('index.twig', $context, $GLOBALS['cache_duration']);
I was just wondering if this was the best solution or if there was a more timber-specific way of doing this? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions