mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
53d3f1e6cd
Summary: We would like to use a limited size LRU cache fore trees as well as blobs, so I am templatizing this to allow us to use this cache for trees. Trees will not need to use Interest handles, but in the future we could use this cache for blob metadata, which might want to use interest handles. Additionally if we at somepoint change the inode tree scheme that would remove the tree content from the inodes itself, interest handle might be useful for trees. We could also use this cache proxy hashes which may or may not use interest handles. Since some caches may want interest handles and others will not I am creating get/insert functions that work with and without interest handles. Reviewed By: chadaustin Differential Revision: D27797025 fbshipit-source-id: 6db3e6ade56a9f65f851c01eeea5de734371d8f0
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#include "eden/fs/store/BlobAccess.h"
|
|
#include <folly/MapUtil.h>
|
|
#include "eden/fs/model/Blob.h"
|
|
#include "eden/fs/store/BlobCache.h"
|
|
#include "eden/fs/store/IObjectStore.h"
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
BlobAccess::BlobAccess(
|
|
std::shared_ptr<IObjectStore> objectStore,
|
|
std::shared_ptr<BlobCache> blobCache)
|
|
: objectStore_{std::move(objectStore)}, blobCache_{std::move(blobCache)} {}
|
|
|
|
BlobAccess::~BlobAccess() {}
|
|
|
|
folly::Future<BlobCache::GetResult> BlobAccess::getBlob(
|
|
const Hash& hash,
|
|
ObjectFetchContext& context,
|
|
BlobCache::Interest interest) {
|
|
auto result = blobCache_->get(hash, interest);
|
|
if (result.object) {
|
|
return folly::Future<BlobCache::GetResult>{std::move(result)};
|
|
}
|
|
|
|
return objectStore_->getBlob(hash, context)
|
|
.thenValue([blobCache = blobCache_,
|
|
interest](std::shared_ptr<const Blob> blob) {
|
|
auto interestHandle = blobCache->insert(blob, interest);
|
|
return BlobCache::GetResult{std::move(blob), std::move(interestHandle)};
|
|
});
|
|
}
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|