This article describes how to use memcache in zendframework and analyzes the specific steps and implementation code of zendframework to call memcache, for more information about how to use memcache in zend framework, see the following example. We will share this with you 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 used to initialize and load all operations ):
Protected function _ initMemcache () {$ frontendOpts = array ('caching' => true, 'lifetime' => 1800, // cache life cycle of 3 minutes, set 'ic IC _ serialization' => true) according to your project requirements; $ backendOpts = array ('servers' => array ('host' => '100. 0.0.1 ', 'Port' => 11211), 'compression' => false); $ memcache = Zend_Cache: factory ('core', 'memcached', $ frontendOpts, $ backendOpts); Zend_Registry: set ('memcache', $ memcache );}
2. Call at the desired location:
For example, call the link 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 ;}