2015-04-02 08:59:43 +02:00
|
|
|
#include <messmer/blockstore/implementations/caching/CachedBlockRef.h>
|
|
|
|
#include <messmer/blockstore/implementations/caching/CachingBlockStore.h>
|
2015-03-31 14:02:24 +02:00
|
|
|
#include <cassert>
|
2015-03-19 11:16:20 +01:00
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
using std::make_unique;
|
|
|
|
using std::string;
|
2015-03-31 14:02:24 +02:00
|
|
|
using std::mutex;
|
|
|
|
using std::lock_guard;
|
|
|
|
using std::promise;
|
2015-03-19 11:16:20 +01:00
|
|
|
|
|
|
|
namespace blockstore {
|
2015-04-02 08:59:43 +02:00
|
|
|
namespace caching {
|
2015-03-19 11:16:20 +01:00
|
|
|
|
2015-04-02 08:59:43 +02:00
|
|
|
CachingBlockStore::CachingBlockStore(unique_ptr<BlockStore> baseBlockStore)
|
2015-04-02 13:12:29 +02:00
|
|
|
: _baseBlockStore(std::move(baseBlockStore)) {
|
2015-03-28 18:44:22 +01:00
|
|
|
}
|
2015-03-19 11:16:20 +01:00
|
|
|
|
2015-04-02 08:59:43 +02:00
|
|
|
unique_ptr<Block> CachingBlockStore::create(size_t size) {
|
2015-03-31 14:02:24 +02:00
|
|
|
auto block = _baseBlockStore->create(size);
|
2015-04-02 13:12:29 +02:00
|
|
|
return CachingStore::add(std::move(block));
|
2015-03-19 11:16:20 +01:00
|
|
|
}
|
|
|
|
|
2015-04-02 08:59:43 +02:00
|
|
|
unique_ptr<Block> CachingBlockStore::load(const Key &key) {
|
2015-04-02 13:12:29 +02:00
|
|
|
return CachingStore::load(key);
|
2015-03-31 14:02:24 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 11:16:20 +01:00
|
|
|
|
2015-04-02 08:59:43 +02:00
|
|
|
void CachingBlockStore::remove(unique_ptr<Block> block) {
|
2015-04-02 13:12:29 +02:00
|
|
|
return CachingStore::remove(std::move(block));
|
|
|
|
}
|
2015-03-31 14:02:24 +02:00
|
|
|
|
2015-04-02 13:12:29 +02:00
|
|
|
const Key &CachingBlockStore::getKey(const Block &block) const {
|
|
|
|
return block.key();
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<Block> CachingBlockStore::loadFromBaseStore(const Key &key) {
|
|
|
|
return _baseBlockStore->load(key);
|
|
|
|
}
|
2015-03-31 14:02:24 +02:00
|
|
|
|
2015-04-02 13:12:29 +02:00
|
|
|
void CachingBlockStore::removeFromBaseStore(unique_ptr<Block> block) {
|
|
|
|
return _baseBlockStore->remove(std::move(block));
|
2015-03-19 11:16:20 +01:00
|
|
|
}
|
|
|
|
|
2015-04-02 08:59:43 +02:00
|
|
|
uint64_t CachingBlockStore::numBlocks() const {
|
2015-03-19 11:16:20 +01:00
|
|
|
return _baseBlockStore->numBlocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|