Phpmemcache cache none? Php *** Memcache cache operation ** @ authorhxm * @ version1.0 * @ since2015.05.04 * classMCacheextendsObjectimplementsCacheFace {private $ memnull; Mem object private $ sId1; servier service ID *** initialize Memcache ** @ retur
Phpmemcache cache none? Php/*** Memcache cache operation * @ author hxm * @ version 1.0 * @ since 2015.05.04 */class MCache extends Object implements CacheFace {private $ mem = null; // Mem object private $ sId = 1; // servier service ID/*** initialize Memcache ** @ retur
Php memcache Cache <无>
Mem = new Memcache ();} /*** link memcahce service ** @ accessprivate * @ paramstring $ key keyword * @ paramstring $ value cached content * @ returnarray */private function connect ($ sid) {$ file = $ this-> CacheFile (); require $ file; if (! Isset ($ cache) {throw new QException ('cache configuration file does not exist '. $ file) ;}$ server = $ cache [$ this-> cacheId]; $ sid = isset ($ sid) = 0? $ This-> sId: $ sid; // select if (! $ Server [$ sid]) {throw new QException ('current cache server configuration file does not exist');} $ host = $ server [$ sid] ['host']; $ port = $ server [$ sid] ['Port']; try {$ this-> mem-> connect ($ host, $ port);} catch (Exception $ e) {exit ('memecache connection failed, error message :'. $ e-> getMessage ());}} /*** write cache ** @ accessprivate * @ paramstring $ key keyword * @ paramstring $ value cached content * @ returnarray */public function set ($ key, $ value, $ sid, $ expire = 0) {$ data = $ this-> g Et ($ key, $ sid); // if the key value if ($ data) {return $ this-> mem-> set ($ key, $ value, MEMCACHE_COMPRESSED, $ expire);} else {return $ this-> mem-> add ($ key, $ value, MEMCACHE_COMPRESSED, $ expire );}} /*** read cache ** @ accessprivate * @ paramstring $ key keyword * @ param int $ sid select the number of memcache servers * @ returnarray */public function get ($ key, $ sid) {$ this-> connect ($ sid); return $ this-> mem-> get ($ key);}/*** clean (delete) stored All elements of ** @ accessprivate * @ returnarray */public function flush () {$ this-> connect (); return $ this-> mem-> flush ();} /*** Delete cache ** @ accessprivate * @ paramstring $ key keyword * @ param int $ sid select the number of memcache servers * @ returnarray */public function remove ($ key, $ sid) {$ this-> connect (); return $ this-> mem-> delete ($ key );} /* destructor * finally disable memcache */public function _ destruct () {/* if (! $ This-> mem) {$ this-> mem-> close ();}*/}}