diff --git a/README.MD b/README.MD index d631d14..c6967a3 100644 --- a/README.MD +++ b/README.MD @@ -19,8 +19,6 @@ Similar as [dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html) ,but support - - ## Configuration All the configuration on `godns.conf` a TOML formating config file. @@ -46,6 +44,8 @@ If multi `namerserver` set at resolv.conf, the upsteam server will try in order #### cache +Only the local memory storage backend implemented now. The redis backend is in todo list + diff --git a/cache.go b/cache.go index 9a996cf..490dc5e 100644 --- a/cache.go +++ b/cache.go @@ -4,6 +4,7 @@ import ( "crypto/md5" "encoding/json" "fmt" + "github.com/hoisie/redis" "github.com/miekg/dns" "time" ) @@ -47,10 +48,9 @@ type Cache interface { } type MemoryCache struct { - backend map[string]*dns.Msg - serializer *JsonSerializer - expire time.Duration - maxcount int + backend map[string]*dns.Msg + expire time.Duration + maxcount int } func (c *MemoryCache) Get(key string) (*dns.Msg, error) { @@ -60,11 +60,6 @@ func (c *MemoryCache) Get(key string) (*dns.Msg, error) { return nil, KeyNotFound{key} } - // mesg := new(dns.Msg) - // if err := c.serializer.Loads([]byte(data), &mesg); err != nil { - // fmt.Println(err) - // return nil, SerializerError{} - // } return mesg, nil } @@ -73,13 +68,6 @@ func (c *MemoryCache) Set(key string, mesg *dns.Msg) error { if c.Full() && !c.Exists(key) { return CacheIsFull{} } - // data, err := c.serializer.Dumps(mesg) - - // if err != nil { - // return SerializerError{} - // } - - // c.backend[key] = string(data) c.backend[key] = mesg return nil } @@ -105,21 +93,28 @@ func (c *MemoryCache) Full() bool { return c.Length() >= c.maxcount } -// type RedisCache struct{ -// backend redis.client -// } +/* +TODO: Redis cache backend +*/ -// func (c *RedisCache) Get(key string) { +type RedisCache struct { + backend *redis.Client + serializer JsonSerializer + expire time.Duration + maxcount int +} -// } +func (c *RedisCache) Get() { -// func (c *RedisCache) Set() { +} -// } +func (c *RedisCache) Set() { -// func (c &RedisCache) Remove(){ +} -// } +func (c *RedisCache) Remove() { + +} func KeyGen(q Question) string { h := md5.New() diff --git a/godns.conf b/godns.conf index 85285e0..d6bd407 100644 --- a/godns.conf +++ b/godns.conf @@ -28,6 +28,7 @@ file = "" [cache] # backend option [memory|redis] +# redis backend not implemented yet backend = "memory" expire = 600 # 10 minutes maxcount = 100000 diff --git a/handler.go b/handler.go index d2877ce..adb7e69 100644 --- a/handler.go +++ b/handler.go @@ -42,18 +42,18 @@ func NewHandler() *GODNSHandler { switch cacheConfig.Backend { case "memory": cache = &MemoryCache{ - backend: make(map[string]*dns.Msg), - serializer: new(JsonSerializer), - expire: cacheConfig.Expire, - maxcount: cacheConfig.Maxcount, + backend: make(map[string]*dns.Msg), + expire: cacheConfig.Expire, + maxcount: cacheConfig.Maxcount, } case "redis": - cache = &MemoryCache{ - backend: make(map[string]*dns.Msg), - serializer: new(JsonSerializer), - expire: cacheConfig.Expire, - maxcount: cacheConfig.Maxcount, - } + // cache = &MemoryCache{ + // backend: make(map[string]*dns.Msg), + // serializer: new(JsonSerializer), + // expire: cacheConfig.Expire, + // maxcount: cacheConfig.Maxcount, + // } + panic("Redis cache backend not implement yet") default: logger.Printf("Invalid cache backend %s", cacheConfig.Backend) panic("Invalid cache backend")