The following is a PHP cache file implementation class, according to my experience, the cache file is based on the user set time and the file generated during the day and the current time to compare, and then determine whether you need to regenerate the cache file. */
The following is a PHP tutorial cache file Implementation class, according to my experience, the cache file is based on the user set time and the file generated during the day and the current time to compare, and then determine whether you need to regenerate the cache file. */
Class Pagecache {
/**
* @var string $file cache file Address
* @access Public
*/
public $file;
/**
* @var int $cachetime Cache time
* @access Public
*/
public $cachetime = 3600;
/**
* Constructor function
* @param string $file cache file Address
* @param int $cachetime Cache time
*/
function __construct ($file, $cachetime = 3600) {
$this->file = $file;
$this->cachetime = $cachetime;
}
/**
* Fetch Cached content
* @param bool Direct output, true go directly to cache page, false return cached content
* @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 Contents
* @param $content Content HTML string
*/
Public function set ($content) {
$fp = fopen ($this->file, ' W ');
Fwrite ($fp, $content);
Fclose ($FP);
}
}
http://www.bkjia.com/PHPjc/444822.html www.bkjia.com true http://www.bkjia.com/PHPjc/444822.html techarticle The following is a PHP cache file implementation class, according to my experience, the cache file is based on the user set time and the file generated during the day and the current time to compare, and then determine whether ...