_php instances of methods using Memcache in the Zend Framework

Source: Internet
Author: User
Tags zend zend framework

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.