connect(self::MEMCACHE_HOST, self::MEMCACHE_PORT) === false) {
throw new Exception('Could not connect', 0);
}
}
/**
* Singleton accessor
*
* @return Atom_Cache_Main
*/
public static function instance() {
if(self::$_instance == null) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Adds $object to the cache, accessable by $key
*
* @param string $key
* @param mixed $object
* @param int $timeout Timespan the object is hold in the cache in seconds
*/
public function add($key, $object, $timeout = null) {
self::$_memcache->set(
$key,
$object,
false,
($timeout === null ? self::MEMCACHE_STD_TIMEOUT : $timeout)
);
}
/**
* Retrieves stored data
*
* @param string $key Identifier
* @return mixed Stored data by memcache
*/
public function get($key) {
return self::$_memcache->get($key);
}
}
?>