-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEviction.h
84 lines (71 loc) · 1.74 KB
/
Eviction.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef BaseLib_Policy_Eviction_h_IsIncluded
#define BaseLib_Policy_Eviction_h_IsIncluded
#include"BaseLib/Templates/BaseTypes.h"
#include"BaseLib/Export.h"
namespace BaseLib { namespace Policy
{
/**
* Enumerated value
*/
namespace EvictionKind
{
enum Type
{
LEAST_RECENTLY_USED,
LEAST_FREQUENTLY_USED
};
}
/**
* Policy to decide which objects to evict from the cache once ResourceLimits
* or Lifespan policies trigger.
*
* Also known as Replacement policy in cache algorithms.
*
* TODO: Add "number of items to evict"?
*
* @author KVik
*/
class DLL_STATE Eviction : public Templates::ComparableImmutableType<EvictionKind::Type>
{
public:
/**
* User defined ejection strategy, otherwise the ejection strategy is default.
*
* @param ejectionKind
*/
Eviction(EvictionKind::Type kind = EvictionKind::LEAST_RECENTLY_USED)
: Templates::ComparableImmutableType<EvictionKind::Type>(kind)
{ }
virtual ~Eviction()
{ }
EvictionKind::Type Kind() const
{
return this->Clone();
}
// ----------------------------------
// Static convenience functions
// ----------------------------------
/**
* @return Ejection with policy to evict objects based on least recently used
*/
static Eviction LeastRecentlyUsed()
{
return Eviction(EvictionKind::LEAST_RECENTLY_USED);
}
/**
* @return Ejection with policy to evict objects based on least frequently used
*/
static Eviction LeastFrequentlyAccessed()
{
return Eviction(EvictionKind::LEAST_FREQUENTLY_USED);
}
/**
* Default is least recently used.
*/
static Eviction Default()
{
return LeastRecentlyUsed();
}
};
}}
#endif