zf框架的zend_cache缓存使用方法(zend框架)_PHP

WBOY
Release: 2016-06-01 11:55:39
Original
1164 people have browsed it

Zend_Cache文件缓存的基本操作,代码中有已写注释,大家共同学习一下吧
复制代码 代码如下:
require_once("Zend/Loader.php");
//载入Zend缓存类(Zend_Cache)
Zend_Loader::loadClass("Zend_Cache");
//前端缓存设置(生命周期、是否序列化)
$Foptions = array('lifetime' => 60 , 'automtic_Serialization' => true);
//后端缓存设置(缓存存放路径)
$Boptions = array('cacheDir' => 'cache');
//开启缓存模式,(Core[核心],File[文件],前端缓存配置信息,后端缓存配置信息)
$Cache = Zend_Cache::factory('Core','File',$Foptions,$Boptions);
//判断缓存是否存在,如果存在则载入缓存load('String'[缓存名称])
if ($Result = $Cache -> load('cache_two'))
{
 echo "缓存已经存在!
";
 print_r($Result);
}
else
{
 //如果缓存不存在则读取文件,并将文件内容写入湖缓存
 echo "缓存不存在!
";
 $Filename = 'temp.txt';
 $Fopen    = fopen($Filename,'r');
 $Result   = fread($Fopen, filesize($Filename));
 fclose($Fopen);
 //保存缓存方式load($Result[读取资源],'缓存名称')
 $Cache -> save($Result,'cache_two');
 print_r($Result);
}
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!