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.