Join the Conversation


  1. This is awesome Kevin,
    thank you very much for sharing…
    any chance to have a downloadable code example?
    Thank you!

  2. Hi Kevin,

    great insights here. Already implemented get and the approach in my theme ;). I’m interested how does the cache method looks like. Would you mind sharing it? I tried to find in the Roots Sage forked repo that your former company maintains but no luck there.

    1. Hi Marcin—

      The cache method depends on what you’re trying to cache and how long it should persist. If you are able to cache particular results of complex logic for a few minutes or more, I’d recommend putting those results in a transient. For example, you might want to compile a list of related posts based on custom criteria, and you could store the post IDs for the related posts for a specific post in a transient and cache it for 15 minutes or a few hours, depending on how quickly your content changes.

      In my case, I was performing a lookup that might originate in a few different places within the same file, but I only wanted the results to be cached for the current request. In that case, I created a class variable in my theme class and stored the result of the query there. When I needed to do a lookup, I would see if the value existed in the member variable first, and if it did not, I would perform the lookup and cache the results.

Leave a comment

Your email address will not be published. Required fields are marked *