MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / CacheServer

Class CacheServer

example/cacheCluster/include/cacheServer.hpp:29–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27namespace CDNSimulator {
28
29class CacheServer {
30 public:
31 unsigned long _server_id;
32 // the number of caches in this server
33
34 // the caches in this server
35 std::vector<Cache> _cache_vec;
36
37 /* availability simulation */
38 bool _available = true;
39
40 CacheServer(unsigned long server_id) { this->_server_id = server_id; }
41
42 CacheServer(const CacheServer& other) = delete;
43
44 CacheServer(CacheServer&& other) {
45 this->_server_id = other._server_id;
46 this->_cache_vec = std::move(other._cache_vec);
47 this->_available = other._available;
48 };
49
50 CacheServer& operator=(const CacheServer& other) = delete;
51
52 CacheServer& operator=(CacheServer&& other) {
53 this->_server_id = other._server_id;
54 this->_cache_vec = std::move(other._cache_vec);
55 this->_available = other._available;
56 return *this;
57 };
58
59 /**
60 * @brief add a cache to this server
61 * return the index of the cache in this server
62 *
63 * @param cache
64 * @return size_t
65 */
66 inline size_t add_cache(Cache&& cache) {
67 // this->_cache_vec.emplace_back(cache_size, cache_alg, hashpower);
68
69 this->_cache_vec.push_back(std::move(cache));
70 return this->_cache_vec.size() - 1;
71 }
72
73 inline bool get(request_t* req) {
74 if (!_available) return false;
75
76 for (int i = 0; i < this->_cache_vec.size(); i++) {
77 // check each cache in this server
78 bool hit = this->_cache_vec.at(i).get(req);
79
80 if (hit) return true;
81 }
82
83 return false;
84 }
85
86 inline bool set_unavailable() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected