Home > Backend Development > PHP Tutorial > zend framework中使用memcache的方法_PHP

zend framework中使用memcache的方法_PHP

WBOY
Release: 2016-05-28 11:47:50
Original
921 people have browsed it

本文实例讲述了zend framework中使用memcache的方法。分享给大家供大家参考,具体如下:

zend framework项目中,以下是具体方法:

1.找到Bootstrap.php添加以下初始化方法(注意:Bootstrap.php是初始化加载所有的操作):

protected function _initMemcache()
{
$frontendOpts = array(
'caching' => true,
'lifetime' => 1800, //缓存生命周期3分钟,根据自己项目需求设置
'automatic_serialization' => true
);
$backendOpts = array(
'servers' =>array(
array(
'host' => '127.0.0.1',
'port' => 11211
)
),
'compression' => false
);
$memcache = Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts);
Zend_Registry::set('memcache',$memcache);
}

Copy after login

2.在你所需的位置调用即可:

例如在你的IndexController中调用友情链接

public function indexAction(){
 $memcache=Zend_Registry::get('memcache');
 //友情链接
 if(!$datalink = $memcache->load('datalink')){
 $link=new Blog_Model_Friendlink();
 $datalink = $link->listshi ();//print_r($datalink);die;
 $memcache->save($datalink, 'datalink');
 }
 $this->view->datalink=$datalink;
}

Copy after login

更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

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