function delete_cache($domain, $page) { $filepath = get_cache_pathname($domain, $page); if (file_exists($filepath)) { unlink($filepath); } }
function set_cache($domain, $page) { global $base_url; $callback = 'genetify.handleResults'; $reader_response = file_get_contents("{$base_url}/reader.php?callback={$callback}&domain={$domain}&page={$page}"); if (!strstr($reader_response, $callback)) { errback('Read failure: ' . $reader_response); } $filepath = get_cache_pathname($domain, $page); //TODO: atomic file replace $fh = fopen($filepath, 'w'); $success = fwrite($fh, $reader_response); fclose($fh); if (!$success) { errback('Write failure: ' . $filepath); } }