-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCache.cpp
More file actions
57 lines (43 loc) · 1.13 KB
/
Cache.cpp
File metadata and controls
57 lines (43 loc) · 1.13 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
//
// Created by mano on 10.12.16.
//
#include "Cache.h"
#include <iostream>
#include <fstream>
Cache::Cache() {
}
bool Cache::is_in_cache(std::pair<std::string, std::string> key) {
fprintf(stderr, "Check in cache: %s %s\n", key.first.c_str(), key.second.c_str());
bool result = (bool) cache.count(key);
return result;
}
Buffer * Cache::get_from_cache(std::pair<std::string, std::string> key) {
fprintf(stderr, "Get from cache: %s %s\n", key.first.c_str(), key.second.c_str());
if (!cache.count(key)) {
return NULL;
}
else {
return cache[key];
}
}
void Cache::delete_from_cache(std::pair<std::string, std::string> key) {
if (!cache.count(key)) {
return;
}
if (cache[key] != NULL) {
delete cache[key];
}
cache.erase(key);
}
int Cache::push_to_cache(std::pair<std::string, std::string> key, Buffer * data) {
fprintf(stderr, "Push to cache: %s %s\n", key.first.c_str(), key.second.c_str());
if (cache.count(key)) {
delete cache[key];
}
cache[key] = data;
}
Cache::~Cache() {
for (auto elem : cache) {
delete elem.second;
}
}