Is it possible to save an entire piece of rendered HTML in a transient?
-
16-10-2019 - |
Pergunta
I have some query that brings around 50+ posts (I know it's not ideal but had to do that to build something the client asked..) and a set of loops to order them in a certain way and it looks like that this sequence is delaying parts of the rendering of the page.
I'd like to cache in a transient this entire block of rendered HTML, is that possible?
Solução
Transients API documentation formulates suggested usage as:
long/expensive database queries or complex processed data
Your case seems like a perfect fit for this description. On technical side you will need to concatenate your output into variable and put into transient, instead of displaying it.
Outras dicas
If I were to implement this today, my preference would be the memcache object cache, storing the data using wp_cache_set()
, possibly updating the data using WP_Cron rather than during page load.
Just how many kilobytes are we talking about?