File indexing completed on 2025-01-18 10:02:33
0001 #pragma once
0002
0003 #include <vector>
0004 #include <iostream>
0005 #include <chrono>
0006 #include <queue>
0007 #include <nlohmann/json.hpp>
0008
0009 #include <nopayloadclient/exception.hpp>
0010
0011
0012 namespace nopayloadclient {
0013
0014 using nlohmann::json;
0015 using std::string;
0016
0017 class Cache {
0018 public:
0019 Cache() {};
0020 Cache(const json& config);
0021
0022
0023
0024 bool contains(const string& url);
0025
0026 json get(const string& url);
0027
0028
0029
0030 void set(const string& url, json& response);
0031 void trash();
0032 friend std::ostream& operator<< (std::ostream& os, const Cache& c);
0033
0034 private:
0035
0036 json response_dict_;
0037
0038 json time_stamp_dict_;
0039
0040 std::queue<string> insertion_order_;
0041 void removeOldestEntry();
0042 bool isAboveMaxSize();
0043 double getSize();
0044 bool isEmpty();
0045 long long getNowTs();
0046 unsigned int life_time_;
0047 unsigned int max_mb_;
0048 };
0049
0050 }