00001 <?php
00010 class Cache_MemCache extends Cache
00011 {
00012 var $memcache = null;
00013
00014
00015 var $active = false;
00016
00020 function Cache_MemCache()
00021 {
00022 $this->Cache();
00023 $this->memcache = new Memcache();
00024 $this->active = false;
00025
00026 if(defined('CACHE_MEMCACHE_SERVERS')) {
00027 foreach(explode(' ', CACHE_MEMCACHE_SERVERS) as $tuple) {
00028 list($h,$p) = explode(':', $tuple);
00029 $this->add_server($h, $p);
00030 }
00031 }
00032 }
00033
00034 function add_server($host, $port)
00035 {
00036 if($this->memcache->addServer($host, $port)) $this->active = true;
00037 return $this->active;
00038 }
00039
00040 function set($key, $var, $expire=0)
00041 {
00042 $key = SITE_NAME."|$key";
00043 return $this->active ? $this->memcache->set($key, $var, 0, $expire) : false;
00044 }
00045
00046 function &get($key)
00047 {
00048 $key = SITE_NAME."|$key";
00049 if(!$this->active) return false;
00050 $val =& $this->memcache->get($key);
00051 return $val;
00052 }
00053
00054 function delete($key)
00055 {
00056 if(!$this->active) return false;
00057 $key = SITE_NAME."|$key";
00058 return $this->memcache->delete($key);
00059 }
00060
00061 function flush()
00062 {
00063 if(!$this->active) return false;
00064 return $this->memcache->flush();
00065 }
00066
00067 function gc()
00068 {
00069
00070 }
00071
00072 function stats()
00073 {
00074 if(!$this->active) return false;
00075 return $this->memcache->getExtendedStats();
00076 }
00077 }
00078
00079 ?>