date_sub(now(), interval 1 hour)"; $linkroll_cache_result = mysql_query($linkroll_cache_query); //if a count was returned, we should use cache and NOT make an api call if (mysql_result($linkroll_cache_result,0) >= 1) { //use the linkroll cache $linkroll_data = get_last_cached_data('linkroll'); } else { //no cache so time to update our cache with a new data fetched from the api do_api_call('/posts/recent?','count=20'); //if status is 200 then create the cache and use $api_return for our data. //otherwise, fetch the cache data instead. if ($api_return['status'] == 200) { $add_cache_query = sprintf( "insert into linkroll (time_retrieved,serialized_data_array) values (now(),'%s')", mysql_real_escape_string(serialize($api_return)) ); mysql_query($add_cache_query) or die(mysql_error()); $linkroll_data = $api_return; } else { //otherwise, force using the cache $linkroll_data = get_last_cached_data('linkroll'); } } //next let’s fill $tagroll_data with the tags for this user for our tagroll //using the API $tagroll_data = array(); //start by seeing if the first (and only) row in the tagroll table has a // time_retrieved that is in the last hour $tagroll_cache_query = "select count(*) from tagroll where time_retrieved > date_sub(now(), interval 1 hour)"; $tagroll_cache_result = mysql_query($tagroll_cache_query); //if a count was returned, we should use cache and NOT make an api call if (mysql_result($tagroll_cache_result,0) >= 1) { //use the tagroll cache $tagroll_data = get_last_cached_data('tagroll'); } else { //no cache so time to update our cache with a new data fetched from the api do_api_call('/tags/get'); //if status is 200 then create the cache and use $api_return for our data. //otherwise, fetch the cache data instead. if ($api_return['status'] == 200) { $add_cache_query = sprintf( "insert into tagroll (time_retrieved,serialized_data_array) values (now(),'%s')", mysql_real_escape_string(serialize($api_return)) ); mysql_query($add_cache_query) or die(mysql_error()); $tagroll_data = $api_return; } else { //otherwise, force using the cache $tagroll_data = get_last_cached_data('tagroll'); } } //this function will grab the links for a particular tag, whether from //cache or a del.icio.us API call function get_tag_linkroll($tag) { global $api_return; //tag_linkroll_data with be filled with the 20 latest posted bookmarks //under $tag $tag_linkroll_data = array(); //check for cache like with the normal linkroll but also query on the tag name $tag_linkroll_cache_query = "select * from tag_linkroll where time_retrieved > date_sub(now(), interval 1 hour) and tag='".mysql_real_escape_string($tag)."'"; $tag_linkroll_cache_result = mysql_query($tag_linkroll_cache_query); //if a row was returned, we should use cache and NOT make an api call if (mysql_num_rows($tag_linkroll_cache_result) >= 1) { //use the tag linkroll cache $tag_linkroll_data = get_last_cached_data('tag_linkroll',$tag); } else { //no cache so time to update our cache with a new data fetched from the api do_api_call('/posts/recent?',"count=20&tag=".$tag); //if status is 200 then create the cache and use $api_return for our data. //otherwise, fetch the cache data instead. if ($api_return['status'] == 200) { $add_cache_query = sprintf( "insert into tag_linkroll (time_retrieved,serialized_data_array,tag) values (now(),'%s','%s')", mysql_real_escape_string(serialize($api_return)), mysql_real_escape_string($tag) ); mysql_query($add_cache_query) or die(mysql_error()); $tag_linkroll_data = $api_return; } else { //otherwise, force using the cache $tag_linkroll_data = get_last_cached_data('tag_linkroll',$tag); } } //return the list with proper html formatting $posts = $tag_linkroll_data[0]['children']; $html = "selected tag: $tag"; $html .= "
".$post['attributes']['EXTENDED']."
"; } $html .= "