Memcache Operation class

Source: Internet
Author: User
Tags md5 encryption codeigniter

<?PHP/** * Memcache Operation implementation * @author Timeless*/classMemcache_manage {//CI Original information    Private $_ci; Private $_memcache_prefix; Private $host; Private $port; Private $expire; Private $weight; /** * Read profile information and update * @access Public*/     Public functionMemcache$flag= ' Default ') {        //to access CodeIgniter's original resources in your custom class library, you must use the Get_instance () function. This function returns a CodeIgniter Super object.        $this->_ci = &get_instance (); //record the data in the Memcache cache configuration//memcached

/* configuration information in the memcahed.php file in the CI framework$config=Array( //It is now a separate Memcache server that can add more than just the Mem object to add Addserver' Default ' =Array( ' Hostname ' = ' 127.0.0.1 ', ' port ' = ' 11211 ', ' weight ' = ' 1 ',//100 minutes' Expire ' = ' 6000 ', ' memcache_prefix ' and ', ' ),); */ $this->_ci->config->load (' memcached ',FALSE,TRUE); //Get configuration file $default _conf=$this->_ci->config->item (' Default '); $this->host =$default _conf[' hostname ']; $this->port =$default _conf[' Port ']; $this->expire =$default _conf[' Expire ']; $this->weight =$default _conf[' Weight ']; $this->_memcache_prefix =$default _conf[' Memcache_prefix ']; $this->connected_server =Array(); $this-_connect (); } /** * Connect memcache database * @access Private*/ Private function_connect () {if(function_exists(' Memcache_connect ')) { $this->cache =NewMemcache; $this-_connect_memcached (); } } /** * Add memcache Server * @access private*/ Private function_connect_memcached () {$error _display=Ini_get(' Display_errors '); $error _reporting=Ini_get(' error_reporting '); if($this->cache->addserver ($this->host,$this->port,TRUE,$this-weight)) { $this->connected_server[] =$this-host; } Ini_set(' error_reporting ',$error _reporting); } Public functionGet$key) { if(Empty($this-connected_server)) { return false; } return $this->cache->get ($this->key_name ($key)); } Public functionSet$key,$data) { if(Empty($this-connected_server)) { return false; } return $this->cache->set ($this->key_name ($key),$data, 0,$this-expire); } Public functionSet_expire ($key,$data,$expire) { if(Empty($this-connected_server)) { return false; } return $this->cache->set ($this->key_name ($key),$data, 0,$expire); } Public functionReplace$key,$data) { if(Empty($this-connected_server)) { return false; } return $this->cache->replace ($this->key_name ($key),$data, 0,$this-expire); } Public functionDelete$key,$when= 0) { if(Empty($this-connected_server)) { return false; } return $this->cache->delete ($this->key_name ($key),$when); } Public function Flush() { return $this->cache->Flush(); } /** * @Name: Unique key value after generating MD5 encryption * @param: $key key * @return: MD5 String **/ Private functionKey_name ($key) { return MD5(Strtolower($this->_memcache_prefix.$key)); }}

Memcache Operation 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.