The examples in this article describe the ways in which memcache is used in the Zend Framework. Share to everyone for your reference, specific as follows:
In the Zend Framework project, the following are the specific methods:
1. Find bootstrap.php Add the following initialization method ( Note: bootstrap.php is initialized to load all operations ):
protected function _initmemcache ()
{
$frontendOpts = array (
' caching ' => true,
' lifetime ' => 1800,//cache lifecycle 3 minutes, set
' Automatic_serialization ' => true according to your own project requirements
;
$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. Call at the location you want:
For example, call the links in your Indexcontroller
Public Function indexaction () {
$memcache =zend_registry::get (' memcache ');
Links
if (! $datalink = $memcache->load (' Datalink ')) {
$link =new blog_model_friendlink ();
$datalink = $link->listshi ();//print_r ($datalink);d ie;
$memcache->save ($datalink, ' datalink ');
}
$this->view->datalink= $datalink;
}
More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.