libcryfs/implementations/caching/CachingBlockStore.cpp

43 lines
1012 B
C++
Raw Normal View History

#include "CachedBlockRef.h"
#include "CachingBlockStore.h"
#include <cassert>
2015-04-02 18:19:05 +02:00
#include "CachingBlockStoreAdapter.h"
using std::unique_ptr;
using std::make_unique;
using std::string;
using std::mutex;
using std::lock_guard;
using std::promise;
namespace blockstore {
namespace caching {
CachingBlockStore::CachingBlockStore(unique_ptr<BlockStore> baseBlockStore)
2015-04-02 18:19:05 +02:00
: _baseBlockStore(std::move(baseBlockStore)), _cachingStore(make_unique<CachingBlockStoreAdapter>(_baseBlockStore.get())) {
}
unique_ptr<Block> CachingBlockStore::create(size_t size) {
auto block = _baseBlockStore->create(size);
2015-04-02 13:21:52 +02:00
Key key = block->key();
2015-04-02 18:19:05 +02:00
return _cachingStore.add(key, std::move(block));
}
unique_ptr<Block> CachingBlockStore::load(const Key &key) {
2015-04-02 18:19:05 +02:00
return _cachingStore.load(key);
}
void CachingBlockStore::remove(unique_ptr<Block> block) {
2015-04-02 13:21:52 +02:00
Key key = block->key();
2015-04-02 18:19:05 +02:00
return _cachingStore.remove(key, std::move(block));
}
uint64_t CachingBlockStore::numBlocks() const {
return _baseBlockStore->numBlocks();
}
}
}