Skip to content

Commit

Permalink
Rename cache to hunt.cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujiaqing committed Aug 27, 2018
1 parent 0ee8490 commit 50192b2
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 301 deletions.
54 changes: 27 additions & 27 deletions dub.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cache",
"name": "hunt-cache",
"dependencies": {
"kiss":{"version":"~>0.4.0"}
},
Expand All @@ -10,34 +10,34 @@
],
"license": "Apache-2.0",
"configurations":[
{
"name":"default",
"dependencies": {
"dredis": {"version" :"~>0.0.8" }
{
"name":"default",
"dependencies": {
"dredis": {"version" :"~>0.0.8" }
},
"versions":["SUPPORT_REDIS"]
},
"versions":["SUPPORT_REDIS"]
},
{
"name":"normal",
"dependencies": {
"dredis": {"version" :"~>0.0.8" },
"libmemcached":{"version":"~>1.1.1"}
{
"name":"normal",
"dependencies": {
"dredis": {"version" :"~>0.0.8" },
"libmemcached":{"version":"~>1.1.1"}
},
"versions":["SUPPORT_REDIS","SUPPORT_MEMCACHED"]
},
"versions":["SUPPORT_REDIS","SUPPORT_MEMCACHED"]
},
{
"name":"full",
"dependencies": {
"dredis": {"version" :"~>0.0.8" },
"libmemcached":{"version":"~>1.1.1"},
"rocksdb":{"version" :"~>0.0.7"}
{
"name":"full",
"dependencies": {
"dredis": {"version" :"~>0.0.8" },
"libmemcached":{"version":"~>1.1.1"},
"rocksdb":{"version" :"~>0.0.7"}
},
"lflags": ["-L./lib"],
"libs": ["rocksdb","zstd"],
"versions":["SUPPORT_MEMCACHED" , "SUPPORT_REDIS" , "SUPPORT_ROCKSDB"]
},
"lflags": ["-L./lib"],
"libs": ["rocksdb","zstd"],
"versions":["SUPPORT_MEMCACHED" , "SUPPORT_REDIS" , "SUPPORT_ROCKSDB"]
},
{
"name":"none"
},
{
"name":"none"
}
]
}
2 changes: 1 addition & 1 deletion example/source/app.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module example;
import huntlabs.cache;
import hunt.cache;


struct Student
Expand Down
32 changes: 14 additions & 18 deletions source/huntlabs/cache/cache.d → source/hunt/cache/cache.d
Original file line number Diff line number Diff line change
@@ -1,83 +1,81 @@
module huntlabs.cache.cache;
module hunt.cache.cache;

import huntlabs.cache.nullable;
import huntlabs.cache.l2cache;
import hunt.cache.nullable;
import hunt.cache.l2cache;



final class Cache(T )
final class Cache(T)
{

Nullable!V get_ex(V)(string key)
Nullable!V get_ex(V)(string key)
{
if(_t !is null)
return _t.get!V(key);
else
return _t2.get!V(key);
}

V get(V)(string key)
V get(V)(string key)
{
return cast(V)get_ex!V(key);
}

Nullable!V[string] getall(V)(string[] keys)
Nullable!V[string] getall(V)(string[] keys)
{
if(_t !is null)
return _t.getall!V(keys);
else
return _t2.getall!V(keys);
}

bool containsKey(string key)
bool containsKey(string key)
{
if(_t !is null)
return _t.containsKey(key);
else
return _t2.containsKey(key);
}

void put(V)(string key , V v , uint expired = 0)
void put(V)(string key , V v , uint expired = 0)
{
if(_t !is null)
return _t.put!V(key , v , expired);
else
return _t2.put!V(key , v , expired);
}

bool putifAbsent(V)(string key , V v)
bool putifAbsent(V)(string key , V v)
{
if( _t !is null)
return _t.putifAbsent!V(key , v);
else
return _t2.putifAbsent!V(key , v);
}

void putAll(V)( V[string] maps , uint expired = 0)
void putAll(V)( V[string] maps , uint expired = 0)
{
if(_t !is null)
return _t.putAll!V(maps , expired);
else
return _t2.putAll!V(maps , expired);
}

bool remove(string key)
bool remove(string key)
{
if(_t !is null)
return _t.remove(key);
else
return _t2.remove(key);
}

void removeAll(string[] keys)
void removeAll(string[] keys)
{
if(_t !is null)
return _t.removeAll(keys);
else
return _t2.removeAll(keys);
}

void clear()
void clear()
{
if(_t !is null)
return _t.clear();
Expand All @@ -93,8 +91,6 @@ final class Cache(T )
_t = new T(args);
}



private:

T _t;
Expand Down
27 changes: 13 additions & 14 deletions source/huntlabs/cache/l2cache.d → source/hunt/cache/l2cache.d
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module huntlabs.cache.l2cache;

import huntlabs.cache.memory;
import huntlabs.cache.nullable;
module hunt.cache.l2cache;

import hunt.cache.memory;
import hunt.cache.nullable;

final class L2Cache(T)
{
Nullable!V get(V)(string key)
Nullable!V get(V)(string key)
{
synchronized(this){
auto v1 = _memory.get!V(key);
Expand All @@ -23,7 +22,7 @@ final class L2Cache(T)
}
}

Nullable!V[string] getall(V)(string[] keys)
Nullable!V[string] getall(V)(string[] keys)
{
synchronized(this){
Nullable!V[string] mapv;
Expand All @@ -36,22 +35,22 @@ final class L2Cache(T)
}
}

bool containsKey(string key)
bool containsKey(string key)
{
synchronized(this){
return _cache.containsKey(key);
}
}

void put(V)(string key , V v , uint expired = 0)
void put(V)(string key , V v , uint expired = 0)
{
synchronized(this){
_cache.put!V(key , v , expired);
_memory.put!V(key , v , expired);
}
}

bool putifAbsent(V)(string key , V v)
bool putifAbsent(V)(string key , V v)
{
synchronized(this){
if( _cache.putifAbsent!V(key , v))
Expand All @@ -64,15 +63,15 @@ final class L2Cache(T)
return false;
}

void putAll(V)( V[string] maps , uint expired = 0)
void putAll(V)( V[string] maps , uint expired = 0)
{
synchronized(this){
_cache.putAll!V(maps , expired);
_memory.putAll!V(maps , expired);
}
}

bool remove(string key)
bool remove(string key)
{
synchronized(this){
auto ret = _cache.remove(key);
Expand All @@ -81,15 +80,15 @@ final class L2Cache(T)
}
}

void removeAll(string[] keys)
void removeAll(string[] keys)
{
synchronized(this){
_cache.removeAll(keys);
_memory.removeAll(keys);
}
}

void clear()
void clear()
{
synchronized(this){
_cache.clear();
Expand All @@ -106,4 +105,4 @@ final class L2Cache(T)
private:
MemoryCache _memory;
T _cache;
}
}
4 changes: 2 additions & 2 deletions source/huntlabs/cache/manger.d → source/hunt/cache/manger.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module huntlabs.cache.manger;
import huntlabs.cache.ucache;
module hunt.cache.manger;
import hunt.cache.ucache;

class CacheManger
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
module huntlabs.cache.memcached;
module hunt.cache.memcached;

import huntlabs.cache.cache;
import huntlabs.cache.store;
import huntlabs.cache.nullable;


version(SUPPORT_MEMCACHED){

import memcache.memcache;
import hunt.cache.cache;
import hunt.cache.store;
import hunt.cache.nullable;

version(SUPPORT_MEMCACHED):

import memcache.memcache;

class MemcachedCache
{

Nullable!V get(V)(string key)
Nullable!V get(V)(string key)
{
synchronized(this){
return get_inter!V(key);
Expand Down Expand Up @@ -135,5 +132,3 @@ protected:


}
}

Loading

0 comments on commit 50192b2

Please sign in to comment.