Implement is_present directly in MemcacheBlobstore

Summary:
When I implement a cachemutex to keep the herd from all trying to
write the same blob multiple times, we'll be able to accelerate this. In the
short term, move the implementation up to here so that the change will be
obvious when it's put up for review.

Reviewed By: jsgf

Differential Revision: D8318152

fbshipit-source-id: f117c5fd834cab55ace10ac46bffa881457c840a
This commit is contained in:
Simon Farnsworth 2018-06-08 06:33:30 -07:00 committed by Facebook Github Bot
parent 59ddd45a41
commit 9b98afc9a4

View File

@ -128,4 +128,22 @@ impl<T: Blobstore + Clone> Blobstore for MemcacheBlobstore<T> {
bs_put.and_then(move |_| mc_put).boxify()
}
fn is_present(&self, key: String) -> BoxFuture<bool, Error> {
let mc_check = self.mc_get(&key).map(|blob| blob.is_some());
let bs_check = future::lazy({
let blobstore = self.blobstore.clone();
move || blobstore.is_present(key)
});
mc_check
.and_then(|blob| {
if blob {
Either::A(Ok(true).into_future())
} else {
Either::B(bs_check)
}
})
.boxify()
}
}