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

Class Cache

example/cacheCluster/include/cache.hpp:22–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20namespace CDNSimulator {
21
22class Cache {
23 private:
24 cache_t* _cache = nullptr;
25 unsigned long _cache_size;
26
27 public:
28 Cache(const Cache& other) = delete;
29
30 Cache(Cache&& other) {
31 this->_cache = clone_cache(other._cache);
32 this->_cache_size = other._cache_size;
33 };
34
35 Cache& operator=(const Cache& other) = delete;
36
37 Cache& operator=(Cache&& other) = delete;
38
39 Cache(const uint64_t cache_size, const std::string cache_alg,
40 const uint32_t hashpower = 20) {
41 this->_cache_size = cache_size;
42
43 common_cache_params_t params;
44 params.cache_size = cache_size;
45 params.consider_obj_metadata = false;
46 params.hashpower = hashpower;
47
48 if (strcasecmp(cache_alg.c_str(), "lru") == 0) {
49 this->_cache = LRU_init(params, NULL);
50 } else if (strcasecmp(cache_alg.c_str(), "fifo") == 0) {
51 this->_cache = FIFO_init(params, NULL);
52 } else {
53 ERROR("unknown cache replacement algorithm %s\n", cache_alg.c_str());
54 abort();
55 }
56
57 srand((unsigned int)time(nullptr));
58 }
59
60 inline bool get(request_t* req) {
61 return this->_cache->get(this->_cache, req);
62 }
63
64 ~Cache() { this->_cache->cache_free(this->_cache); }
65};
66} // namespace CDNSimulator
67
68#endif

Callers 1

simulateFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected