--- oldcache.php 2010-03-01 20:04:54.000000000 -0500 +++ newcache.php 2010-03-01 20:17:18.000000000 -0500 @@ -1,34 +1,9 @@ pconnect(MEMCACHED_HOST, MEMCACHED_PORT); + parent::__construct("lolgazelle"); + Memcached::setOption(Memcached::OPT_COMPRESSION, false); + Memcached::setOption(Memcached::OPT_NO_BLOCK, true); + Memcached::setOption(Memcached::OPT_CACHE_LOOKUPS, true); + Memcached::setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT); + Memcached::setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true); + + //uncomment if you have the json extension loaded + //Memcached::setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_JSON); + + //uncomment if you have memcached >=1.3.0 and libmemcached >=0.28 + //Memcached::setOptions(Memcached::OPT_BINARY_PROTOCAL, true); + + Memcached::setOption(Memcached::OPT_PREFIX_KEY, SERVER_ROOT); //lolz, change plz + + if(count($this->getServerList()) < 1) { + $this->addServer(MEMCACHED_HOST, MEMCACHED_PORT); + } + //$this->connect('localhost', 11211); } - //---------- Caching functions ----------// - - // Allows us to set an expiration on otherwise perminantly cache'd values - // Useful for disabled users, locked threads, basically reducing ram usage public function expire_value($Key, $Duration=2592000) { $StartTime=microtime(true); $this->set($Key, $this->get($Key), $Duration); $this->Time+=(microtime(true)-$StartTime)*1000; } - // Wrapper for Memcache::set, with the zlib option removed and default duration of 1 hour public function cache_value($Key, $Value, $Duration=2592000) { $StartTime=microtime(true); if (empty($Key)) { @@ -62,6 +50,17 @@ $this->Time+=(microtime(true)-$StartTime)*1000; } + public function set($key, $val) { + $args = func_get_args(); + if(func_num_args() === 3) { + $duration = $args[2]; + } else { + $duration = $args[3]; + } + + Memcached::set($key, $val, $duration); + } + public function replace_value($Key, $Value, $Duration=2592000) { $StartTime=microtime(true); $this->replace($Key, $Value, false, $Duration);