Php Cache Technology example

Source: Internet
Author: User

Php Cache Technology example the php cache technology mentioned in this Article is to generate a temporary cache file for data and save it to the hard disk, then, delete the cached file and generate a new cache file based on the time set for the cached file.

Php tutorial Cache Technology example
The php cache technology mentioned in this Article is to generate a temporary cache file for data and save it to the hard disk. Then, delete the cache file according to the time set by the cache file to generate a new cache file again.
*/

$ Filename = 'cachefile. php ';
$ Str = 'echo "bb ";';
If (is_file ($ filename ))
{
$ Tmp = readcache ($ filename );
}
Else
{
Createcache ($ filename, $ str );
}

// Write the cached File

Function createcache ($ filename, $ str)
{
If ($ str = '') {return false ;}
$ Fp = fopen ($ filename, "w +") or die ('the cache directory is not possible. Set/www. bKjia. c0m/cache to writable! ');
If (! Fwrite ($ fp, $ str ))
{
Echo 'the cache file cannot be created! ';
Exit;
}
Fclose ($ fp );
}

// Read the cached File

Function readcache ($ filename)
{
$ Str = file_get_contents ($ filename );
If ($ str = "")
{
Echo "An error occurred while reading the cached file! ";
Exit;
}
Return $ str;
}

/*
Original Site article, reprinted with source http://www.bKjia. c0m/phper/php.html
*/

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.