1 module hunt.cache.adapter.MemcacheAdapter; 2 3 // import hunt.cache.adapter.Adapter; 4 // import hunt.cache.Store; 5 6 // import hunt.cache.Nullable; 7 8 // version(WITH_HUNT_MEMCACHE): 9 10 // import memcache.memcache; 11 // import hunt.cache.CacheOptions; 12 13 // class MemcacheAdapter : Adapter 14 // { 15 // Nullable!V get(V) (string key) 16 // { 17 // synchronized(this) 18 // { 19 // return get_inter!V(key); 20 // } 21 // } 22 23 // Nullable!V[string] getAll(V) (string[] keys) 24 // { 25 // //Memcache's bug not implement mget. 26 // //so it's not atomic operation, and transfer .keys.length. times througth network 27 // synchronized(this) 28 // { 29 // Nullable!V[string] mapv; 30 // if(keys.length == 0) 31 // return mapv; 32 33 // foreach(k ; keys){ 34 // mapv[k] = get_inter!V(k); 35 // } 36 37 // return mapv; 38 // } 39 // } 40 41 // bool hasKey(string key) 42 // { 43 // //Memcache's bug not implement exist, use get inside of. 44 // synchronized(this) 45 // { 46 // return _cache.get!string(key).length > 0; 47 // } 48 // } 49 50 // void set(V) (string key, V v, uint expired) 51 // { 52 // synchronized(this) 53 // { 54 // put_inter!V(key, v, expired); 55 // } 56 // } 57 58 // bool setIfAbsent(V) (string key, const V v) 59 // { 60 // synchronized(this){ 61 62 // if(hasKey(key)) 63 // return false; 64 65 // put_inter!V(key, v, 0); 66 // return true; 67 // //return _cache.replace(key, cast(string)SerializeToByte!V(v)); 68 // } 69 // } 70 71 // // because memcached api no mset api, so is cost much time to put many. 72 // void set(V) (V[string] maps, uint expired) 73 // { 74 // synchronized(this) 75 // { 76 // foreach(k, v ; maps) 77 // { 78 // put_inter!V(k, v, expired); 79 // } 80 // } 81 // } 82 83 // bool remove(string key) 84 // { 85 // synchronized(this) 86 // { 87 // return remove_inter(key); 88 // } 89 // } 90 91 // // because memcached api no mdel api, so is cost much time to remove many. 92 // void remove(string[] keys) 93 // { 94 // synchronized(this) 95 // { 96 // foreach(k ; keys){ 97 // remove_inter(k); 98 // } 99 // } 100 // } 101 102 // void clear() 103 // { 104 // synchronized(this){ 105 // _cache.flush(); 106 // } 107 // } 108 109 // this(CacheOptions.MemcacheConf config) 110 // { 111 // import std.conv : to; 112 113 // string args = "--SERVER=" ~ config.host ~ ":" ~ config.port.to!string; 114 // _cache = new Memcache(args); 115 // } 116 117 // protected: 118 // Memcache _cache; 119 120 // Nullable!V get_inter(V) (string key) 121 // { 122 // string data = _cache.get(key); 123 // return DeserializeToObject!V(cast(byte[])data); 124 // } 125 126 // void put_inter(V) (string key, V v, uint expired) 127 // { 128 // _cache.set(key, cast(string)SerializeToByte(v), cast(int)expired); 129 // } 130 131 // bool remove_inter(string key) 132 // { 133 // return _cache.del(key); 134 // } 135 // }