Integrating WP-TLC-Transients with WordPress – Where to Begin?

Place wherever your code can access Include tlc-transients.php during your plugin/theme load (or otherwise before init hook) Follow examples from readme for library’s API use PS in [still not very common] case you are using Composer you can also just require markjaquith/wp-tlc-transients in composer.json.

WordPress transients for a shortcode

Use this instead of the line in wich you define $days (your second line): $transient = get_transient( ‘your_transient_key’ ); if( !$transient ): $days = file_get_contents( ‘json_file’ ); set_transient( ‘your_transient_key’, $days, DAY_IN_SECONDS*7 ); else: $days = $transient; endif; $days = json_decode( $days ); … May be a bit rough but you get the idea.

Fragment caching increasing database queries

You are using transient API which works storing data on wp_options table by default. That means that additional database queries will be performed to set the transient and to get the transient. With your code the number of queries should be less for non-logged in users in second and subsequent visits when the transient exists … Read more

How to save new transients if query changes?

According to code in OP, the only thing that changes the result is the $tags variable. In this case, the easiste way to do the trick is make the $tags part of the transient name. function get_posts_by_tags($tags){ $transient=”rest-posts-” . md5(serialize($tags)); if(false === ($result = get_transient($transient))) { // the rest of yout function here … if … Read more

Fallback when Transient API fails

Mark Jaquith made a “TLC Transients” method that you might find useful. Essentially, it implements a transient interface that does soft expiration and background updating. https://github.com/markjaquith/WP-TLC-Transients The idea is that you define a function to do the call that gets the data, then define the transient and pass it that function as a callback. When … Read more

What’s the case against transient-ing almost everything that’s mostly static?

Actually, doing it for menu is good, you can even store entire HTML output and cut not only queries, but processing time too. Additionally, you can use WP_Object_Cache directly in conjunction with Redis/Memcached backend and avoid even single DB query for the transient itself. Re comments – they do change, so running WP_Comment_Query is unavoidable. … Read more