PHP File Caching Technology implementation Code _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.