--- oldcache.php 2010-03-01 20:04:54.000000000 -0500 +++ newcache.php 2010-03-01 20:05:17.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)) { @@ -236,6 +224,16 @@ } } + public function lolbutts() { + $val = $cache->get("this_is_a_key", function($memcached_instance, $key, &$val) { + if(OORZA_IS_AWESOME) { //always true, but still... + $val = "Holy shit this is a new value OMFG"; + return true; //HOLY FUCK MEMCACHED JUST READ THROUGH AND SET THE KEY __AND__ RETURNED IT! AIN'T THAT SOME SHIT + } else { + return false; //Poor lil $val gets ignored and the key doesn't get set + } + }); + } // Insert a value at the beginning of the array public function insert_front($Key, $Value) { if (!$this->InTransaction) {