Php packaging memcache class-php Tutorial

Source: Internet
Author: User
Php encapsulation memcache class & lt ;? Php * & nbsp; * memcache class & nbsp; * classMemcacheds {& nbsp; declare static member variables & nbsp; privatestatic $ mnull; & nbsp; privatestatic $ ca php encapsulation memcache class
/*
* Memcache class
*/
Class Memcacheds {
// Declare static member variables
Private static $ m = null;
Private static $ cache = null;

Private function _ construct (){
Self: $ m = new Memcache ();
Self: $ m-> connect ('www .cat.com ', '000000'); // write cache address, Port
}

// Create an object for the current class
Private static function Men (){
Self: $ cache = new Memcacheds ();
Return self: $ m;
}

/*
* Add cache data
* @ Param string $ key obtains the unique key of the data.
* @ Param String | Array $ value cached data
* @ Param $ time memcache lifecycle (seconds)
*/
Public static function setMen ($ key, $ value, $ time ){
Self: Men ()-> set ($ key, $ value, 0, $ time );
}
/*
* Obtain cache data
* @ Param string $ key
* @ Return
*/
Public static function getMen ($ key ){
Return self: Men ()-> get ($ key );
}
/*
* Delete the corresponding cached data
* @ Param string $ key
* @ Return
*/
Public static function delMen ($ key ){
Self: Men ()-> delete ($ key );
}
/*
* Delete all cached data
*/
Public static function delAllMen (){
Self: Men ()-> flush ();
}

/*
* Delete all cached data
*/
Public static function menStatus (){
Return self: Men ()-> getStats ();
}

}


<----------------------------------------------------------->

Call class

Include_once 'memcache. php'; introduce class files

$ Key = 'MyKey ';
$ Value = 'Insert into 12334234 ';
$ Time = 60;
Memcacheds: setMen ($ key, $ value, $ time); // write cache

$ Get = Memcacheds: getMen ($ key); // Read

Echo'

';
Print_r ($ get );

?>

Result output:

insert into 12334234


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.