<?PHP/** * @example $mem = new Memcached (); * @example $getCache = $mem->get (' Test '); * @example memcache_host Host * @examp Le memcache_port Port * @example memcache_timeout Cache time*/classMemcached {Private$memcache =NULL; /** * @desc Constructors*/ Publicfunction __construct () {$ This->memcache =NewMemcache; $ This->memcache->Connect (memcache_host, Memcache_port, memcache_timeout); } /** * Compatible with PHP4*/ Publicfunction Memcached () {$ This-__construct (); } /** * @desc Gets the value of memcache based on key * @param string $name Key name * @return Array or string*/ PublicfunctionGet($name, $isJson =true) {$value= $ This->memcache->Get($name); if($isJson) $value= Json_decode ($value,true); return$value; } /** * Set the cache, if it exists on the update, does not exist then add, if successful returns TRUE, Failure returns FALSE. * @param string $name Key name * @param array or array $value value value * @param boolean $ttl whether to compress * @param int $ext 1 used to set an expired auto-destroy time * @return Boolean*/ PublicfunctionSet($name, $value, $ext 1 =false, $ttl =0) { return$ This->memcache->Set($name, $value, $ext 1, $ttl); } /** * Add cache, return TRUE if successful, or FALSE if unsuccessful. * @param string $name Key name * @param array or array $value value value * @param boolean $ttl whether to compress * @param int $ext 1 used to set an expired auto-destroy time * @return Boolean*/ Publicfunction Add ($name, $value, $ext 1 =false, $ttl =0) { return$ This->memcache->Add ($name, $value, $ext 1, $ttl); } /** * @desc Delete the cache, returns TRUE if successful, and FALSE if it fails. * @param string $name Key Name * @return Boolean*/ Publicfunction Delete ($name) {return$ This->memcache->Delete ($name); } /** * @desc Close a Memcache object * @return Blloean*/ Publicfunction Close () {return$ This->memcache->Close (); } /** * @desc Increment item ' s value (addition operation) * @param string $name * @param int $value Increment the item by V Alue. Optional and Defaults to 1. * @return Type*/ Publicfunction Increment ($name, $value) {return$ This->memcache->Increment ($name, $vlaue); } /** * @desc Decrement item ' s value (subtraction operation) * @param string $name * @param int $value Decrement the item by V Alue. Optional and Defaults to 1. * @return Type*/ Publicfunction Decrement ($name, $value) {return$ This->memcache->Decrement ($name, $vlaue); } /** * @desc get run system statistics for all processes in the process pool * @return Array*/ Publicfunction Getextendedstats () {return$ This->memcache->getextendedstats (); } /** * @desc returns some running statistics for the server * @return Array*/ Publicfunction GetStats () {return$ This->memcache->getstats (); } /** * @desc empties the cache, returns TRUE if successful, and FALSE if it fails. * @return Boolean*/ Publicfunction Flush () {return$ This->memcache->Flush (); }}?>
PHP script memcache class source code