-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathcache.hpp
More file actions
69 lines (51 loc) · 1.5 KB
/
cache.hpp
File metadata and controls
69 lines (51 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// cache.cpp
// CDNSimulator
//
// Created by Juncheng on 11/18/18.
// Copyright © 2018 Juncheng. All rights reserved.
//
#ifndef CDNSIMULATOR_CACHE_HPP
#define CDNSIMULATOR_CACHE_HPP
#include <inttypes.h>
#include <algorithm>
#include <iostream>
#include "libCacheSim/cache.h"
#include "libCacheSim/evictionAlgo.h"
namespace CDNSimulator {
class Cache {
private:
cache_t* _cache = nullptr;
unsigned long _cache_size;
public:
Cache(const Cache& other) = delete;
Cache(Cache&& other) {
this->_cache = clone_cache(other._cache);
this->_cache_size = other._cache_size;
};
Cache& operator=(const Cache& other) = delete;
Cache& operator=(Cache&& other) = delete;
Cache(const uint64_t cache_size, const std::string cache_alg,
const uint32_t hashpower = 20) {
this->_cache_size = cache_size;
common_cache_params_t params;
params.cache_size = cache_size;
params.consider_obj_metadata = false;
params.hashpower = hashpower;
if (strcasecmp(cache_alg.c_str(), "lru") == 0) {
this->_cache = LRU_init(params, NULL);
} else if (strcasecmp(cache_alg.c_str(), "fifo") == 0) {
this->_cache = FIFO_init(params, NULL);
} else {
ERROR("unknown cache replacement algorithm %s\n", cache_alg.c_str());
abort();
}
srand((unsigned int)time(nullptr));
}
inline bool get(request_t* req) {
return this->_cache->get(this->_cache, req);
}
~Cache() { this->_cache->cache_free(this->_cache); }
};
} // namespace CDNSimulator
#endif