neic-glass3  1.4.6
cache.h
Go to the documentation of this file.
1 /*****************************************
2  * This file is documented for Doxygen.
3  * If you modify this file please update
4  * the comments so that Doxygen will still
5  * be able to work.
6  ****************************************/
7 #ifndef CACHE_H
8 #define CACHE_H
9 
10 #include <baseclass.h>
11 #include <json.h>
12 #include <logger.h>
13 
14 #include <mutex>
15 #include <string>
16 #include <map>
17 #include <memory>
18 
19 namespace glass3 {
20 namespace util {
30 class Cache : public util::BaseClass {
31  public:
38  Cache();
39 
45  virtual ~Cache();
46 
53  void clear() override;
54 
64  virtual bool addToCache(std::shared_ptr<json::Object> data, std::string id);
65 
74  virtual bool removeFromCache(std::string id);
75 
84  virtual bool isInCache(std::string id);
85 
96  virtual std::shared_ptr<const json::Object> getFromCache(std::string id);
97 
108  virtual std::shared_ptr<const json::Object> getNextFromCache(
109  bool restart = false);
110 
117  virtual bool isEmpty();
118 
122  int size();
123 
124  private:
128  std::map<std::string, std::shared_ptr<json::Object>> m_Cache;
129 
134  std::map<std::string, std::shared_ptr<json::Object>>::iterator m_CacheDumpItr;
135 
140  std::mutex & getMutex();
141 
145  std::mutex m_Mutex;
146 };
147 } // namespace util
148 } // namespace glass3
149 #endif // CACHE_H
150 
virtual std::shared_ptr< const json::Object > getFromCache(std::string id)
get data from Cache
Definition: cache.cpp:123
virtual bool removeFromCache(std::string id)
remove data from Cache
Definition: cache.cpp:75
virtual bool addToCache(std::shared_ptr< json::Object > data, std::string id)
add data to Cache
Definition: cache.cpp:41
The neic-glass3 project namespace containing all the classes and functions that make up neic-glass3...
glass3::util::BaseClass class - encapsulates the most basic setup and configuration logic...
Definition: baseclass.h:30
virtual ~Cache()
Cache destructor.
Definition: cache.cpp:22
void clear() override
Cache clear function.
Definition: cache.cpp:26
virtual std::shared_ptr< const json::Object > getNextFromCache(bool restart=false)
get next data from Cache
Definition: cache.cpp:145
virtual bool isInCache(std::string id)
check for data in Cache
Definition: cache.cpp:103
int size()
Retrieves the current size of the Cache.
Definition: cache.cpp:180
logger.h contains the interface to the neic-glass3 logging library
Cache()
Cache constructor.
Definition: cache.cpp:17
glass3::util::Cache class - a thread safe in-memory cache
Definition: cache.h:30
virtual bool isEmpty()
check if Cache empty
Definition: cache.cpp:172