I'm looking at making some file swap caching more robust as well as adding a refresh function to it. I'm really new to the idea of caching, but this is what I have right now:

//This is the query string
$q = 'http://pipes.yahoo.com/pipes/Zmn2To672xGonTsUfOgC8A/run?_render=rss';

//cache requesting
function request_cache($url, $dest_file, $timeout=03000) {
  if(!file_exists($dest_file) || filemtime($dest_file) < (time()-$timeout)) {
    $data = file_get_contents($url);
    if ($data === false) return false;
    $tmpf = tempnam('/tmp','YPS');
    $fp = fopen($tmpf, "w");
    fwrite($fp, $data);
   // file_put_contents($tmpf, $data);
    rename($tmpf, $dest_file);
    return $data;
      return file_get_contents($dest_file);
//query loading with cache 
$tmp = '/tmp/yws_pipe_'.md5($q);
request_cache($q, $tmp, 03000);
$xml = simplexml_load_file($tmp, 'cNode') or die ('Unable to load XML file!');
recommendations from the more experienced will be appreciated.