2015-04-15 15:46:35 +02:00
|
|
|
#pragma once
|
2015-10-15 13:09:21 +02:00
|
|
|
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTORE_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTORE_H_
|
2015-04-15 15:46:35 +02:00
|
|
|
|
2015-04-27 22:46:57 +02:00
|
|
|
#include "cache/Cache.h"
|
2015-04-16 14:10:44 +02:00
|
|
|
#include "../../interface/BlockStore.h"
|
2015-04-15 15:46:35 +02:00
|
|
|
|
|
|
|
namespace blockstore {
|
2015-04-16 14:10:44 +02:00
|
|
|
namespace caching {
|
2015-04-15 15:46:35 +02:00
|
|
|
|
2015-04-15 21:46:15 +02:00
|
|
|
//TODO Check that this blockstore allows parallel destructing of blocks (otherwise we won't encrypt blocks in parallel)
|
2015-04-16 14:10:44 +02:00
|
|
|
class CachingBlockStore: public BlockStore {
|
2015-04-15 15:46:35 +02:00
|
|
|
public:
|
2015-07-21 18:19:34 +02:00
|
|
|
explicit CachingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore);
|
2015-04-15 15:46:35 +02:00
|
|
|
|
2015-04-18 14:47:12 +02:00
|
|
|
Key createKey() override;
|
2015-07-20 18:57:48 +02:00
|
|
|
boost::optional<cpputils::unique_ref<Block>> tryCreate(const Key &key, cpputils::Data data) override;
|
2015-07-21 14:50:52 +02:00
|
|
|
boost::optional<cpputils::unique_ref<Block>> load(const Key &key) override;
|
|
|
|
void remove(cpputils::unique_ref<Block> block) override;
|
2015-04-15 15:46:35 +02:00
|
|
|
uint64_t numBlocks() const override;
|
|
|
|
|
2015-07-21 14:50:52 +02:00
|
|
|
void release(cpputils::unique_ref<Block> block);
|
2015-04-15 15:46:35 +02:00
|
|
|
|
2015-07-20 18:57:48 +02:00
|
|
|
boost::optional<cpputils::unique_ref<Block>> tryCreateInBaseStore(const Key &key, cpputils::Data data);
|
2015-07-21 14:50:52 +02:00
|
|
|
void removeFromBaseStore(cpputils::unique_ref<Block> block);
|
2015-04-18 14:47:12 +02:00
|
|
|
|
2015-10-14 14:40:45 +02:00
|
|
|
void flush();
|
|
|
|
|
2015-04-15 19:05:58 +02:00
|
|
|
private:
|
2015-07-21 18:19:34 +02:00
|
|
|
cpputils::unique_ref<BlockStore> _baseBlockStore;
|
2015-10-07 17:24:13 +02:00
|
|
|
Cache<Key, cpputils::unique_ref<Block>, 1000> _cache;
|
2015-04-18 14:47:12 +02:00
|
|
|
uint32_t _numNewBlocks;
|
2015-04-15 15:46:35 +02:00
|
|
|
|
2015-04-16 14:10:44 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CachingBlockStore);
|
2015-04-15 15:46:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|