<?php
/*
* Memcache class
*/
Class memcacheds{
declaring static member variables
private static $m = null;
private static $cache = null;
Private Function __construct () {
Self:: $m = new Memcache ();
Self:: $m->connect (' www.cat.com ', ' 11211 '); Write Cache address, port
}
To create an object for the current class
private static function men () {
Self:: $cache = new Memcacheds ();
Return self:: $m;
}
/*
* Add Cached data
* @param string $key get data Unique key
* @param string| | Array $value Cache Data
* @param $time Memcache Life cycle (sec)
*/
public static function Setmen ($key, $value, $time) {
Self::men ()->set ($key, $value, 0, $time);
}
/*
* Get Cached data
* @param string $key
* @return
*/
public static function Getmen ($key) {
Return Self::men ()->get ($key);
}
/*
* Delete corresponding cache 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
<?php
Include_once ' memcache.php '; Introducing class Files
$key = ' MyKey ';
$value = ' insert into 12334234 ';
$time = 60;
Memcacheds::setmen ($key, $value, $time); Write Cache
$get = Memcacheds::getmen ($key); Read
Echo ' <pre> ';
Print_r ($get);
?>
Result output:
INSERT INTO 12334234
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PHP Package Memcache Class