function yarpp_get_cached_keywords($ID, $type = 'body') { global $wpdb; $out = $wpdb->get_var("select {$type} from {$wpdb->prefix}yarpp_keyword_cache where ID = {$ID}"); if ($out === false or $out == '') { // if empty, try caching them first. yarpp_cache_keywords($ID); $out = $wpdb->get_var("select {$type} from {$wpdb->prefix}yarpp_keyword_cache where ID = {$ID}"); } if ($out === false or $out == '') { // if still empty... return false //echo "<!--YARPP ERROR: couldn't select/create yarpp $type keywords for $ID-->"; return false; } else { return $out; } }
function get_keywords($ID, $type = 'body') { $key = $type == 'body' ? YARPP_POSTMETA_BODY_KEYWORDS_KEY : YARPP_POSTMETA_TITLE_KEYWORDS_KEY; $out = get_post_meta($ID, $key, true); // if empty, try caching them first if ($out === false) { yarpp_cache_keywords($ID); $out = get_post_meta($ID, $key, true); } return $out; }
function yarpp_cache_enforce($type = array('post'), $reference_ID, $force = false) { global $wpdb, $yarpp_debug; if ($reference_ID === '' || $reference_ID === false) { return false; } if (!$force) { if ($wpdb->get_var("select count(*) as count from {$wpdb->prefix}yarpp_related_cache where reference_ID = {$reference_ID}")) { // 3.1.3: removed the cache timeout // and date > date_sub(now(),interval 600 minute) if ($yarpp_debug) { echo "<!--YARPP is using the cache right now.-->"; } return false; } } yarpp_cache_keywords($reference_ID); // clear out the cruft yarpp_cache_clear(array($reference_ID)); // let's update the related posts $wpdb->query("insert into {$wpdb->prefix}yarpp_related_cache (reference_ID,ID,score) " . yarpp_sql($type, array(), true, $reference_ID) . " on duplicate key update date = now()"); $affected = $wpdb->rows_affected; if ($affected and $yarpp_debug) { echo "<!--YARPP just set the cache for post {$reference_ID}-->"; } // if changes were made, let's find out which ones are new. We'll want to clear their caches // so that they will be rebuilt when they're hit next. if ($affected && !yarpp_get_option('past_only')) { $new_relations = $wpdb->get_col("select ID from {$wpdb->prefix}yarpp_related_cache where reference_ID = {$reference_ID} and ID != 0"); yarpp_cache_clear($new_relations); } if (!$affected) { $wpdb->query("insert into {$wpdb->prefix}yarpp_related_cache (reference_ID,ID,score) values ({$reference_ID},0,0) on duplicate key update date = now()"); if (!$wpdb->rows_affected) { return false; } } return true; }