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

前端技术 2023/09/06 PHP

Zend_Cache文件缓存的基本操作,代码中有已写注释,大家共同学习一下吧

复制代码 代码如下:

<?php
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 \"缓存已经存在!<br>\";
 print_r($Result);
}
else
{
 //如果缓存不存在则读取文件,并将文件内容写入湖缓存
 echo \"缓存不存在!<br>\";
 $Filename = \'temp.txt\';
 $Fopen    = fopen($Filename,\'r\');
 $Result   = fread($Fopen, filesize($Filename));
 fclose($Fopen);
 //保存缓存方式load($Result[读取资源],\'缓存名称\')
 $Cache -> save($Result,\'cache_two\');
 print_r($Result);
}
?>

本文地址:https://www.stayed.cn/item/16428

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。