-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryCache.cpp
63 lines (39 loc) · 1.01 KB
/
QueryCache.cpp
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
#include "QueryCache.h"
#include <stdio.h>
#include <iostream>
#include <iterator>
QueryCache::QueryCache()
{
cout << __FILE__<<"@"<<__TIME__;
}
QueryCache::~QueryCache()
{
}
//using namespace std;
const char * QueryCache::putToCache(const char* pCmd, const char* pResult)
{
string key = pCmd;
string value= pResult;
cacheMap.insert(pair<string, string>(key, value));
return NULL;
}
const char * QueryCache::get(const char* pCmd)
{
string key = pCmd;
map<string, string>::iterator itr= cacheMap.find(key);
if(cacheMap.end()==itr){
return NULL;
}
//string value = cacheMap.find(key)->second;
return cacheMap.find(key)->second.data();
}
void QueryCache::report()
{
map<string, string>::iterator itr;
cout << "\nThe map cacheMap is : \n";
cout << "\tKEY\tELEMENT\n";
for (itr = cacheMap.begin(); itr != cacheMap.end(); ++itr) {
cout << '\t' << itr->first
<< '\t' << itr->second << '\n';
}
}