This article mainly introduces the basic operations of Zend_Cache file caching. for a simple example, you can refer to the basic operations of Zend_Cache file caching. Some comments have been written in the code. let's take a look at them.
The code is as follows:
Require_once ("Zend/Loader. php ");
// Load Zend cache class (Zend_Cache)
Zend_Loader: loadClass ("Zend_Cache ");
// Frontend cache settings (lifecycle, serialization or not)
$ Foptions = array ('lifetime' => 60, 'automtic _ serialization' => true );
// Backend cache settings (cache storage path)
$ Boptions = array ('cachedir' => 'cache ');
// Enable the cache mode (Core [Core], File [File], front-end cache configuration information, and backend cache configuration information)
$ Cache = Zend_Cache: factory ('core', 'file', $ Foptions, $ Boptions );
// Determine whether the cache exists. If yes, load the cache ('string' [cache name])
If ($ Result = $ Cache-> load ('cache _ two '))
{
Echo "the cache already exists!
";
Print_r ($ Result );
}
Else
{
// If the cache does not exist, read the file and write the file content to the Lake cache.
Echo "the cache does not exist!
";
$ Filename = 'temp.txt ';
$ Fopen = fopen ($ Filename, 'r ');
$ Result = fread ($ Fopen, filesize ($ Filename ));
Fclose ($ Fopen );
// Load ($ Result [read resource], 'cache name ')
$ Cache-> save ($ Result, 'cache _ two ');
Print_r ($ Result );
}
?>
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.