Class Memcachedinit { Private $memcache; /** * Memcache Cache-Set Cache * Set cache Key,value and cache time * @param string $key key value * @param string $value value * @param string $time cache time */ Public Function Set_cache ($key, $value, $time = 0) { return $this->memcache->set ($key, $value, False, $time); } /** * Memcache Cache-Get Cache * Get cached data through key * @param string $key key value */ Public Function Get_cache ($key) { return $this->memcache->get ($key); } /** * Memcache Cache-Clears a cache * Remove a cache from the Memcache * @param string $key key value */ Public function Clear ($key) { return $this->memcache->delete ($key); } /** * Memcache Cache-Empty all caches * It is not recommended to use this feature * @return */ Public Function Clear_all () { return $this->memcache->flush (); } /** * Field self-used for counting * @param string $key key value * @param int $step The new step value */ Public function Increment ($key, $step = 1) { return $this->memcache->increment ($key, (int) $step); } /** * Field self-minus-for counting * @param string $key key value * @param int $step The new step value */ Public function Decrement ($key, $step = 1) { return $this->memcache->decrement ($key, (int) $step); } /** * Close Memcache Link */ Public function Close () { return $this->memcache->close (); } /** * Replace data * @param string $key The data expected to be replaced * @param string $value the replaced value * @param int $time time value * @param bool $flag whether to compress */ Public function replace ($key, $value, $time = 0, $flag = False) { return $this->memcache->replace ($key, $value, False, $time); } /** * Get the Memcache version number */ Public Function getversion () { return $this->memcache->getversion (); } /** * Get Memcache's state data */ Public Function GetStats () { return $this->memcache->getstats (); } /** * Memcache Caching-setting up a linked server * Support multiple Memcache servers * Configure the Memcache cache server in the configuration file: * $InitPHP _conf[' memcache '][0] = array (' 127.0.0.1 ', ' 11211 '); * @param array $servers server arrays-array (' 127.0.0.1 ', ' 11211 ')) */ Public Function Add_server ($servers) { $this->memcache = new Memcache; if (!is_array ($servers) | | empty ($servers)) exit (' Memcache server is null! '); foreach ($servers as $val) { $this->memcache->addserver ($val [0], $val [1]); } } } How to use $newclass = new Memcachedinit (); $newclass->getversion ()//Get version number $newclass->close ()//close Memcache link $newclass->clear ($key)//Remove a cache from Memcache $newclass->get_cache ($key)//Get cached data via key |