<?php
	have ("cache");

	function cachedURL ($url)
	{
		$cacheDir = siteHome . "/cache";
		$cacheTime = 1800;
		$cacheFile = $cacheDir . '/cached_' . md5 ($url);

		$timeDifference = @(time () - filemtime ($cacheFile));

		if ($cacheTime < $timeDifference) {	// stale, make a new one
			if ($f = @fopen ($url, 'r')) {
				$content = '';
				while (!feof ($f)) {
					$content .= fgets ($f, 4096);
				}
				fclose ($f);
				if ($f = fopen ($cacheFile, 'w')) {
					fwrite ($f, $content, strlen ($content));
					fclose ($f);
				}
			}
		}

		return file ($cacheFile);
	}
?>
