-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKioskcached.cpp
55 lines (50 loc) · 1.36 KB
/
Kioskcached.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
/*************************************************************************
> File Name: Kioskcached.cpp
> Author: YangBodong
> Mail: ybd@xiyoulinux.org
> Created Time: Thu 16 Feb 2017 11:43:35 PM CST
************************************************************************/
#include<iostream>
#include"Kioskcached.h"
#include<assert.h>
Kioskcached::~Kioskcached()
{
}
bool Kioskcached::storeItem(const ItemPtr& item,Item::UpdatePolicy policy,bool *exists)
{
ItemMap::const_iterator it = items.find(item);
*exists = it != items.end();
if(policy == Item::kSet) {
if(*exists) {
items.erase(it);
}
items.insert(item);
}else {
if(policy == Item::kAdd) {
if(*exists) {
return false;
}else {
items.insert(item);
}
}else if(policy == Item::kReplace) {
if(*exists) {
items.erase(it);
items.insert(item);
}else {
return false;
}
}else {
assert(false);
}
}
return true;
}
ConstItemPtr Kioskcached::getItem(const ConstItemPtr& key) const
{
ItemMap::const_iterator it = items.find(key);
return it != items.end() ? *it : ConstItemPtr();
}
bool Kioskcached::deleteItem(const ConstItemPtr& key)
{
return items.erase(key) == 1;
}