BlobStore also returns BlobKey

This commit is contained in:
Sebastian Messmer 2014-12-05 15:37:35 +01:00
parent 24e2d42380
commit b64d352a8c
3 changed files with 15 additions and 5 deletions

View File

@ -10,9 +10,11 @@ namespace ondisk {
OnDiskBlobStore::OnDiskBlobStore(const boost::filesystem::path &rootdir)
: _rootdir(rootdir) {}
unique_ptr<Blob> OnDiskBlobStore::create(const std::string &key, size_t size) {
BlobStore::BlobWithKey OnDiskBlobStore::create(const std::string &key, size_t size) {
auto file_path = _rootdir / key;
return OnDiskBlob::CreateOnDisk(file_path, size);
auto blob = OnDiskBlob::CreateOnDisk(file_path, size);
return BlobStore::BlobWithKey(key, std::move(blob));
}
unique_ptr<Blob> OnDiskBlobStore::load(const std::string &key) {

View File

@ -16,7 +16,7 @@ class OnDiskBlobStore: public BlobStore {
public:
OnDiskBlobStore(const boost::filesystem::path &rootdir);
std::unique_ptr<Blob> create(const std::string &key, size_t size) override;
BlobWithKey create(const std::string &key, size_t size) override;
std::unique_ptr<Blob> load(const std::string &key) override;
private:

View File

@ -5,8 +5,9 @@
#include <string>
#include <memory>
#include "Blob.h"
namespace blobstore {
class Blob;
//TODO Don't use string, but own class for keys? (better performance for all keys have same length)
@ -14,7 +15,14 @@ class BlobStore {
public:
virtual ~BlobStore() {}
virtual std::unique_ptr<Blob> create(const std::string &key, size_t size) = 0;
struct BlobWithKey {
BlobWithKey(const std::string &key_, std::unique_ptr<Blob> &&blob_): key(key_), blob(std::move(blob_)) {}
std::string key;
std::unique_ptr<Blob> blob;
};
virtual BlobWithKey create(const std::string &key, size_t size) = 0;
virtual std::unique_ptr<Blob> load(const std::string &key) = 0;
//TODO Needed for performance? Or is deleting loaded blobs enough?
//virtual void remove(const std::string &key) = 0;