<?php
$present = time();
$cache_url = "http://..."; // URL contains data refresh each day
$cfile = "cache.txt";
if (file_exists($cfile)) {
$handle = fopen($cfile, "r");
$buffer = fgets($handle, 256); // 256 is enough to get data from first line in cache file
$a = split("\r\n", $buffer);
// read cache time at a first line in cache file
$cachetime = $a[0];
fclose($handle);
if ($cachetime + 24 * 60 * 60 < $present) {// recache after 1 day
echo "Cache File Will Be Updated<hr>";
$source = file_get_contents($cache_url);
// save cache time at a first line in cache file
file_put_contents($cfile, $present . "\r\n" . $source);
} else {// cache file is still new
echo "Load From Cached File (cached at " . date("H:i:s d-m-Y", $cachetime) . ")<hr>";
$source = file_get_contents("cache.txt");
}
} else {
$source = file_get_contents($cache_url);
file_put_contents($cfile, $present . "\r\n" . $source);
}
// processing cache data
?>