_Memcache =& new Memcache(); // several servers - use addServer foreach ($this->servers as $server) { $parts = explode(':', $server); $host = $parts[0]; $port = ife(isset($parts[1]), $parts[1], 11211); // default port if ($this->_Memcache->addServer($host, $port)) { $this->_connected = true; } } return $this->_connected; } /** * Set a value in the cache * * Expiration time is one hour if not set */ function set($key, $var, $expires = 3600) { if (defined('DISABLE_CACHE') || !$this->_connected) { return false; } if (!is_numeric($expires)) { $expires = strtotime($expires); } if ($expires < 1) { $expires = 1; // don't allow caching infinitely } return $this->_Memcache->set($key, $var, 0, time()+$expires); } /** * Get a value from cache */ function get($key) { if (defined('DISABLE_CACHE') || !$this->_connected) { return false; } return $this->_Memcache->get($key); } /** * Remove value from cache */ function delete($key) { if (defined('DISABLE_CACHE') || !$this->_connected) { return false; } return $this->_Memcache->delete($key); } } ?>