1 module cachetools.interfaces;
2 
3 import std.typecons;
4 import std.datetime;
5 import std.typecons;
6 
7 private import cachetools.internal;
8 
9 //
10 // cache have aspects:
11 // 1. storage: hashmap and some kind of order of elements
12 // 2. stream of evicted elements, which user may want to handle(slose files, sockets, etc)
13 // 3. eviction policy (condition to start/stop evinction)
14 //
15 
16 enum PutResultFlag {
17     None,
18     Inserted = 1 << 0,
19     Replaced = 1 << 1,
20     Evicted = 1 << 2
21 }
22 
23 alias PutResult = BitFlags!PutResultFlag;
24 
25 // I failed to reach both goals: inheritance from interface and nogc/nothrow attribute neutrality
26 // for Cache implementations. So I droped inheritance.
27 //
28 //interface Cache(K, V) {
29 //
30 //    // get value from cache
31 //    Nullable!V get(K) @safe;
32 //
33 //    // put/update cache entry
34 //    PutResult put(K, V) @safe;
35 //
36 //    // remove key
37 //    bool  remove(K) @safe;
38 //    
39 //    // clear entire cache
40 //    void  clear() @safe;
41 //    
42 //    // # of elements
43 //    size_t length() const @safe;
44 //
45 //}
46 
47 enum EventType {
48     Removed,
49     Expired,
50     Evicted,
51     Updated
52 }
53 
54 struct CacheEvent(K, V) {
55     EventType event;
56     StoredType!K key;
57     StoredType!V val;
58 }