CatapultServer  v0.5.0.1 (Elephant)
ReadOnlySimpleCache.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include <stddef.h>
23 
24 namespace catapult { namespace cache {
25 
27  template<typename TCache, typename TCacheDelta, typename TKey>
28  class ReadOnlySimpleCache {
29  public:
31  explicit ReadOnlySimpleCache(const TCache& cache)
32  : m_pCache(&cache)
33  , m_pCacheDelta(nullptr)
34  {}
35 
37  explicit ReadOnlySimpleCache(const TCacheDelta& cache)
38  : m_pCache(nullptr)
39  , m_pCacheDelta(&cache)
40  {}
41 
42  public:
44  size_t size() const {
45  return m_pCache ? m_pCache->size() : m_pCacheDelta->size();
46  }
47 
50  bool contains(const TKey& key) const {
51  return m_pCache ? m_pCache->contains(key) : m_pCacheDelta->contains(key);
52  }
53 
54  private:
55  const TCache* m_pCache;
56  const TCacheDelta* m_pCacheDelta;
57  };
58 }}
catapult::cache::ReadOnlySimpleCache::m_pCache
const TCache * m_pCache
Definition: ReadOnlySimpleCache.h:55
catapult::cache::ReadOnlySimpleCache::ReadOnlySimpleCache
ReadOnlySimpleCache(const TCacheDelta &cache)
Creates a read-only overlay on top of cache.
Definition: ReadOnlySimpleCache.h:37
catapult::cache::ReadOnlySimpleCache::m_pCacheDelta
const TCacheDelta * m_pCacheDelta
Definition: ReadOnlySimpleCache.h:56
catapult::cache::ReadOnlySimpleCache::size
size_t size() const
Returns the number of elements in the cache.
Definition: ReadOnlySimpleCache.h:44
catapult::cache::ReadOnlySimpleCache::contains
bool contains(const TKey &key) const
Definition: ReadOnlySimpleCache.h:50
catapult::cache::ReadOnlySimpleCache::ReadOnlySimpleCache
ReadOnlySimpleCache(const TCache &cache)
Creates a read-only overlay on top of cache.
Definition: ReadOnlySimpleCache.h:31
catapult
Definition: AddressExtractionExtension.cpp:28