public function add(FedoraResource $res) {
        $uri = $res->getUri(true);
        if (isset($this->cache[$uri])) {
            if (get_class($res) === get_class($this->cache[$uri])) {
                throw new AlreadyInCache();
            } else {
                $this->deleteByUri($uri);
            }
        }
        try {
            $ids                = $res->getIds();
            $this->cache[$uri]  = $res;
            $this->uri2id[$uri] = array();
            foreach ($ids as $id) {
                $this->uri2id[$uri][] = $id;
                $this->id2uri[$id]    = $uri;
            }
        } catch (ClientException $e) {
            switch ($e->getCode()) {
                case 404:
                    throw new NotFound();
                case 410:
                    throw new Deleted();
                default:
                    throw $e;
            }
        }
    }