CatapultServer  v0.5.0.1 (Elephant)
BasicCache.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "CacheConfiguration.h"
23 #include "CacheConstants.h"
24 #include "SynchronizedCache.h"
25 #include "catapult/utils/Casting.h"
26 
27 namespace catapult { namespace cache {
28 
31  template<typename TCacheDescriptor, typename TBaseSet, typename... TSubViewArgs>
32  class BasicCache : public utils::MoveOnly {
33  public:
34  using CacheValueType = typename TCacheDescriptor::ValueType;
35  using CacheViewType = typename TCacheDescriptor::CacheViewType;
36  using CacheDeltaType = typename TCacheDescriptor::CacheDeltaType;
37  using CacheReadOnlyType = typename CacheViewType::ReadOnlyView;
38 
39  public:
41  BasicCache(const CacheConfiguration& config, TSubViewArgs&&... subViewArgs)
42  : m_set(config)
43  , m_subViewArgs(std::forward<TSubViewArgs>(subViewArgs)...)
44  {}
45 
46  public:
49  return createSubView<CacheViewType>(m_set);
50  }
51 
54  return createSubView<CacheDeltaType>(m_set.rebase());
55  }
56 
60  return createSubView<CacheDeltaType>(m_set.rebaseDetached());
61  }
62 
64  void commit(const CacheDeltaType& delta) {
65  Commit(m_set, delta, typename TBaseSet::IsOrderedSet());
66  }
67 
68  private:
69  template<typename TView, typename TSetView>
70  TView createSubView(const TSetView& setView) const {
71  return TView(setView, std::get<TSubViewArgs>(m_subViewArgs)...);
72  }
73 
74  private:
75  static void Commit(TBaseSet& m_set, const CacheDeltaType&, std::false_type) {
76  m_set.commit();
77  }
78 
79  static void Commit(TBaseSet& m_set, const CacheDeltaType& delta, std::true_type) {
80  m_set.commit(delta.pruningBoundary());
81  }
82 
83  private:
84  TBaseSet m_set;
85  std::tuple<TSubViewArgs...> m_subViewArgs;
86  };
87 }}
catapult::cache::BasicCache::createDetachedDelta
CacheDeltaType createDetachedDelta() const
Definition: BasicCache.h:59
catapult::cache::BasicCache::CacheReadOnlyType
typename CacheViewType::ReadOnlyView CacheReadOnlyType
Definition: BasicCache.h:37
catapult::cache::BasicCache::Commit
static void Commit(TBaseSet &m_set, const CacheDeltaType &delta, std::true_type)
Definition: BasicCache.h:79
catapult::cache::BasicCache::commit
void commit(const CacheDeltaType &delta)
Commits all pending changes from delta to the underlying storage.
Definition: BasicCache.h:64
catapult::cache::BasicCache::createSubView
TView createSubView(const TSetView &setView) const
Definition: BasicCache.h:70
SynchronizedCache.h
CacheConstants.h
catapult::cache::BasicCache::CacheViewType
typename TCacheDescriptor::CacheViewType CacheViewType
Definition: BasicCache.h:35
catapult::cache::BasicCache::createView
CacheViewType createView() const
Returns a locked view based on this cache.
Definition: BasicCache.h:48
catapult::cache::BasicCache::Commit
static void Commit(TBaseSet &m_set, const CacheDeltaType &, std::false_type)
Definition: BasicCache.h:75
catapult::cache::BasicCache::CacheValueType
typename TCacheDescriptor::ValueType CacheValueType
Definition: BasicCache.h:34
catapult::cache::BasicCache::m_subViewArgs
std::tuple< TSubViewArgs... > m_subViewArgs
Definition: BasicCache.h:85
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
catapult::cache::BasicCache::createDelta
CacheDeltaType createDelta()
Returns a locked cache delta based on this cache.
Definition: BasicCache.h:53
catapult::cache::BasicCache
Definition: BasicCache.h:32
catapult::cache::BasicCache::CacheDeltaType
typename TCacheDescriptor::CacheDeltaType CacheDeltaType
Definition: BasicCache.h:36
catapult::cache::CacheConfiguration
Cache configuration.
Definition: CacheConfiguration.h:37
catapult::cache::BasicCache::m_set
TBaseSet m_set
Definition: BasicCache.h:84
catapult::cache::BasicCache::BasicCache
BasicCache(const CacheConfiguration &config, TSubViewArgs &&... subViewArgs)
Creates an empty cache with config and arguments (subViewArgs).
Definition: BasicCache.h:41
Casting.h
catapult
Definition: AddressExtractionExtension.cpp:28
CacheConfiguration.h