PHP Package Memcache Class

Source: Internet
Author: User

<?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

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.