CatapultServer  v0.5.0.1 (Elephant)
MemoryCacheProxy.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "MemoryCacheOptions.h"
23 #include <memory>
24 
25 namespace catapult { namespace cache {
26 
28  template<typename TMemoryCache, typename TCache, typename TCacheModifierProxy>
29  class MemoryCacheProxy : public TCache {
30  public:
32  explicit MemoryCacheProxy(const MemoryCacheOptions& options)
33  : m_memoryCache(options)
35  {}
36 
39  template<typename TMutableCacheFactory, typename... TArgs>
40  explicit MemoryCacheProxy(const MemoryCacheOptions& options, TMutableCacheFactory factory, TArgs&&... args)
41  : m_memoryCache(options)
42  , m_pMutableCache(factory(m_memoryCache, std::forward<TArgs>(args)...))
43  , m_pCache(m_pMutableCache.get())
44  {}
45 
46  public:
48  auto view() const {
49  return m_memoryCache.view();
50  }
51 
53  operator const TMemoryCache&() const {
54  return m_memoryCache;
55  }
56 
57  public:
58  TCacheModifierProxy modifier() override {
59  return m_pCache->modifier();
60  }
61 
62  private:
63  TMemoryCache m_memoryCache;
64  std::unique_ptr<TCache> m_pMutableCache;
65  TCache* m_pCache;
66  };
67 }}
catapult::cache::MemoryCacheProxy::m_pMutableCache
std::unique_ptr< TCache > m_pMutableCache
Definition: MemoryCacheProxy.h:64
catapult::cache::MemoryCacheProxy::modifier
TCacheModifierProxy modifier() override
Definition: MemoryCacheProxy.h:58
catapult::cache::MemoryCacheProxy
A delegating proxy around a memory-based cache.
Definition: MemoryCacheProxy.h:29
catapult::cache::MemoryCacheProxy::view
auto view() const
Gets a read only view based on this cache.
Definition: MemoryCacheProxy.h:48
catapult::cache::MemoryCacheProxy::m_memoryCache
TMemoryCache m_memoryCache
Definition: MemoryCacheProxy.h:63
catapult::cache::MemoryCacheProxy::MemoryCacheProxy
MemoryCacheProxy(const MemoryCacheOptions &options, TMutableCacheFactory factory, TArgs &&... args)
Definition: MemoryCacheProxy.h:40
catapult::cache::MemoryCacheProxy::m_pCache
TCache * m_pCache
Definition: MemoryCacheProxy.h:65
MemoryCacheOptions.h
catapult::cache::MemoryCacheProxy::MemoryCacheProxy
MemoryCacheProxy(const MemoryCacheOptions &options)
Creates a proxy around options.
Definition: MemoryCacheProxy.h:32
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::MemoryCacheOptions
Options for customizing the behavior of a memory based cache.
Definition: MemoryCacheOptions.h:27