zend framework中使用memcache的方法,zendmemcache
本文实例讲述了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); }
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; }
更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
- Zend Framework教程之模型Model基本规则和使用方法
- Zend Framework教程之Zend_Layout布局助手详解
- zend framework框架中url大小写问题解决方法
- Zend Framework 2.0事件管理器(The EventManager)入门教程
- Zend Framework页面缓存实例
- 非常好用的Zend Framework分页类
- zend Framework中的Layout(模块化得布局)详解
- zend framework配置操作数据库实例分析
- windows下zendframework项目环境搭建(通过命令行配置)
- Zend Framework教程之模型Model用法简单实例

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools