CatapultServer  v0.5.0.1 (Elephant)
SubCachePlugin.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/types.h"
23 #include <memory>
24 #include <string>
25 
26 namespace catapult {
27  namespace cache {
28  class CacheChangesStorage;
29  class CacheStorage;
30  class CatapultCache;
31  }
32 }
33 
34 namespace catapult { namespace cache {
35 
36  // region SubCacheViewIdentifier
37 
39  enum class SubCacheViewType {
41  View,
42 
44  Delta,
45 
48  };
49 
54  std::array<char, 16> CacheName;
55 
57  size_t CacheId;
58 
61  };
62 
63  // endregion
64 
65  // region SubCacheView / DetachedSubCacheView
66 
68  class SubCacheView {
69  public:
70  virtual ~SubCacheView() = default;
71 
72  public:
74  virtual const SubCacheViewIdentifier& id() const = 0;
75 
77  virtual const void* get() const = 0;
78 
80  virtual void* get() = 0;
81 
83  virtual bool supportsMerkleRoot() const = 0;
84 
86  virtual bool tryGetMerkleRoot(Hash256& merkleRoot) const = 0;
87 
89  virtual bool trySetMerkleRoot(const Hash256& merkleRoot) = 0;
90 
92  virtual void updateMerkleRoot(Height height) = 0;
93 
95  virtual const void* asReadOnly() const = 0;
96  };
97 
100  public:
101  virtual ~DetachedSubCacheView() = default;
102 
103  public:
106  virtual std::unique_ptr<SubCacheView> tryLock() = 0;
107  };
108 
109  // endregion
110 
111  // region SubCachePlugin
112 
115  public:
116  virtual ~SubCachePlugin() = default;
117 
118  public:
120  virtual const std::string& name() const = 0;
121 
123  virtual size_t id() const = 0;
124 
125  public:
127  virtual std::unique_ptr<const SubCacheView> createView() const = 0;
128 
131  virtual std::unique_ptr<SubCacheView> createDelta() = 0;
132 
135  virtual std::unique_ptr<DetachedSubCacheView> createDetachedDelta() const = 0;
136 
138  virtual void commit() = 0;
139 
140  public:
142  virtual const void* get() const = 0;
143 
144  public:
146  virtual std::unique_ptr<CacheStorage> createStorage() = 0;
147 
149  virtual std::unique_ptr<CacheChangesStorage> createChangesStorage() const = 0;
150  };
151 
152  // endregion
153 }}
catapult::cache::SubCacheViewType
SubCacheViewType
Sub cache view types.
Definition: SubCachePlugin.h:39
catapult::cache::SubCachePlugin::createChangesStorage
virtual std::unique_ptr< CacheChangesStorage > createChangesStorage() const =0
Returns a cache changes storage based on this cache.
catapult::cache::SubCachePlugin::id
virtual size_t id() const =0
Gets the cache id.
catapult::cache::SubCachePlugin::createView
virtual std::unique_ptr< const SubCacheView > createView() const =0
Returns a locked cache view based on this cache.
catapult::cache::SubCachePlugin::get
virtual const void * get() const =0
Returns a const pointer to the underlying cache.
catapult::cache::DetachedSubCacheView::~DetachedSubCacheView
virtual ~DetachedSubCacheView()=default
catapult::cache::SubCacheViewIdentifier
Sub cache view identifier.
Definition: SubCachePlugin.h:51
catapult::cache::SubCacheView::get
virtual const void * get() const =0
Returns a const pointer to the underlying view.
catapult::cache::SubCacheView::updateMerkleRoot
virtual void updateMerkleRoot(Height height)=0
Recalculates the merkle root given the specified chain height if supported.
catapult::cache::DetachedSubCacheView
Detached sub cache view.
Definition: SubCachePlugin.h:99
catapult::cache::SubCacheViewIdentifier::ViewType
SubCacheViewType ViewType
View type.
Definition: SubCachePlugin.h:60
catapult::cache::SubCachePlugin::createStorage
virtual std::unique_ptr< CacheStorage > createStorage()=0
Returns a cache storage based on this cache.
catapult::utils::BaseValue< uint64_t, Height_tag >
catapult::cache::SubCacheViewIdentifier::CacheId
size_t CacheId
Cache id.
Definition: SubCachePlugin.h:57
catapult::cache::SubCacheViewType::DetachedDelta
Cache detached delta.
catapult::cache::SubCachePlugin::createDetachedDelta
virtual std::unique_ptr< DetachedSubCacheView > createDetachedDelta() const =0
catapult::cache::SubCacheViewType::View
Cache view.
catapult::cache::SubCachePlugin::createDelta
virtual std::unique_ptr< SubCacheView > createDelta()=0
catapult::cache::SubCacheView
Sub cache view.
Definition: SubCachePlugin.h:68
catapult::cache::SubCachePlugin
Sub cache plugin that can be added to the main catapult cache.
Definition: SubCachePlugin.h:114
catapult::cache::SubCachePlugin::name
virtual const std::string & name() const =0
Gets the cache name.
catapult::cache::SubCacheView::id
virtual const SubCacheViewIdentifier & id() const =0
Gets view identifier.
catapult::cache::SubCachePlugin::commit
virtual void commit()=0
Commits all pending changes to the underlying storage.
types.h
catapult::cache::SubCacheView::~SubCacheView
virtual ~SubCacheView()=default
catapult::cache::SubCacheView::asReadOnly
virtual const void * asReadOnly() const =0
Returns a read-only view of this view.
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::SubCacheViewIdentifier::CacheName
std::array< char, 16 > CacheName
Definition: SubCachePlugin.h:54
catapult::cache::SubCacheView::trySetMerkleRoot
virtual bool trySetMerkleRoot(const Hash256 &merkleRoot)=0
Sets the cache merkle root (merkleRoot) if supported.
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::cache::SubCacheViewType::Delta
Cache delta.
catapult::cache::SubCacheView::tryGetMerkleRoot
virtual bool tryGetMerkleRoot(Hash256 &merkleRoot) const =0
Gets the cache merkle root (merkleRoot) if supported.
catapult::cache::SubCacheView::supportsMerkleRoot
virtual bool supportsMerkleRoot() const =0
Returns true if cache supports merkle root.
catapult::cache::SubCachePlugin::~SubCachePlugin
virtual ~SubCachePlugin()=default
catapult::cache::DetachedSubCacheView::tryLock
virtual std::unique_ptr< SubCacheView > tryLock()=0