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
*/