markjaquith/WP-TLC-Transients — Issue #5: Check for Transient before Running TLC Transients?
Author: adamcapriola
Created: 2011-11-11 14:46:12+00:00
State: open

Yoooo,

I run a database type of website that has a lot of entries (like 5,000 at the moment) and I use TLC Transients for every one of them (and it kicks ass!).

But my CPU usage has gone way up since I started using it - my host says I'm getting a ton of POST request for http://mysite.com/?tlc_transients_request.

I assume that's exactly what's supposed to happen, but I was thinking of checking for a stored transient BEFORE running TLC Transients in my code to save on CPU usage. Is this a good idea, or does it defeat the purpose of it? This is what my function now looks like:

//
// Transient Function (better than just saving transient value)
//
function tlc_price_scraper( $postID = '', $name = '', $set = '', $number = '' ) {

$tlc_name = $postID . '-price'; // Name of value in database.
$cacheTime = 24; // Time in hours between updates.

if ( false === ( $t = get_transient($tlc_name) ) ) {

$t = tlc_transient( $tlc_name )
->updates_with( 'price_scraper', array( $postID, $name, $set, $number ) )
//->expires_in( 5 ) // testing
->expires_in( 60 * 60 * $cacheTime ) // live
//->background_only()
->get();

return $t;
}
else {
return $t[1];
}
}

So I basically just check with get_transient before running tlc_transient. Good idea? Or not?