Class PageCache {
/**
* @ Var string $ file Cache file address
* @ Access public
*/
Public $ file;
/**
* @ Var int $ cacheTime Cache Time
* @ Access public
*/
Public $ cacheTime = 3600;
/**
* Constructor
* @ Param string $ file Cache file address
* @ Param int $ cacheTime Cache Time
*/
Function _ construct ($ file, $ cacheTime = 3600 ){
$ This-> file = $ file;
$ This-> cacheTime = $ cacheTime;
}
/**
* Cache Content Retrieval
* @ Param bool: whether to directly output data. If it is set to true, it is directly transferred to the cache page. If it is set to false, the cached content is returned.
* @ Return mixed
*/
Public function get ($ output = true ){
If (is_file ($ this-> file) & (time ()-filemtime ($ this-> file) <= $ this-> cacheTime &&! $ _ GET ['nocache']) {
If ($ output ){
Header ('location: '. $ this-> file );
Exit;
} Else {
Return file_get_contents ($ this-> file );
}
} Else {
Return false;
}
}
/**
* Set cache content
* @ Param $ content: html string
*/
Public function set ($ content ){
$ Fp = fopen ($ this-> file, 'w ');
Fwrite ($ fp, $ content );
Fclose ($ fp );
}
}