<?php
Define (' Cache_root ', DirName (__file__). /cache '); Cache storage Directory define (' Cache_time ', 1800);//cache time Unit seconds define (' Cache_fix ', '. html '); $CacheName =md5 ($_server[' Request_uri ')). Cache_fix; Cached filename $CacheDir =cache_root. ' /'. substr ($CacheName, 0, 1);//cache file storage Directory $CacheUrl = $CacheDir. ' /'. $CacheName//The full path of the cached file//get the request is cached, after post generally want to see the latest results if ($_server[' request_method ']== ' get ') { //if the cached file exists and does not expire, read it. if (file_exists ($CacheName) && time ()-filemtime ($CacheName) <cache_time) { $FP =fopen ($CacheName, ' RB '); fpassthru ($fp); fclose ($FP); exit;  } //to determine whether a folder exists or not, create elseif (!file_exists ( $CacheDir)) { if (!file_exists (cache_root)) { mkdir (cache_ root,0777); chmod (cache_root,0777); } mkdir ($CacheDir, 0777; chmod ($CacheDir, 0777); } //callback function, which automatically calls this function when the program ends function Autocache ($contents) { global $CacheUrl; $fp = fopen ($CACHEURL, ' WB '); fwrite ($fp, $contents); fclose ($fp); chmod ($CACHEURL, 0777); //generates a new cache while automatically deleting all the old caches to save space and can be ignored. //deloldcache (); return $contents; &NBSP;&NBSP} function Deloldcache () { chdir (cache_root); foreach (Glob ("*/*"). Cache_fix) as $file) { if (Time ()-filemtime ($file) >cache_time) unlink ($file); &NBSP}  } //callback function auto_cache ob_start (' Autocache '); }else{ //Deletes the cached file if it is not a GET request. if (file_exists ($CACHEURL)) unlink ($CACHEURL); }?>