Archived topic
Element Cache
3 replies · Started by Matthew on April 16, 2019
I'm displaying dynamic content in a few elements and the dynamic content requires a few database hits using WP_query. Is there a way to cache the output. Maybe a way so the entire element is cached for a user-defined period of time (ex., 24 hours)? When the period of time expires, the element is refreshed. I don't think this is done already and it could save a lot of resources on my end.
There isn't a way to cache an element, but you could cache your WP_Query results.
For example, run a function in the init hook, and set your query results in update_option() or set_transient().
Then in the element, call the results using get_option() or get_transient().
Thanks. I’ll give that a shot. But maybe you guys could implement element caching and a custom user timer down the road? If not though, np. Thanks!
I'll definitely give it some thought!
Thanks :)