How to use memcache in zend framework, zendmemcache_PHP tutorial

WBOY
Release: 2016-07-12 08:57:57
Original
906 people have browsed it

How to use memcache in zend framework, zendmemcache

This article describes the method of using memcache in zend framework. Share it with everyone for your reference, the details are as follows:

In the zend framework project, the following are the specific methods:

1. Find Bootstrap.php and add the following initialization method (Note: Bootstrap.php is the initialization to load all operations ):

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. Just call it at the location you need:

For example, call friendly links in your 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

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Zend Framework Tutorial: Basic Model Rules and Usage Methods
  • Zend Framework Tutorial: Zend_Layout Layout Assistant Detailed Explanation
  • Solution to the url case problem in zend framework
  • Zend Framework 2.0 Event Manager (The EventManager) introductory tutorial
  • Zend Framework page caching example
  • Very easy to use Zend Framework paging class
  • Detailed explanation of Layout (modular layout) in zend Framework
  • zend framework configuration operation database instance analysis
  • Zendframework project environment construction under windows (via command line Configuration)
  • Zend Framework Tutorial: Simple Example of Model Usage

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106120.htmlTechArticleHow to use memcache in zend framework, zendmemcache This article describes the method of using memcache in zend framework. Share it with everyone for your reference, the details are as follows: zend framew...
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!