diff --git a/cache_memory.go b/cache_memory.go index 9892b50..7af41d8 100644 --- a/cache_memory.go +++ b/cache_memory.go @@ -16,6 +16,10 @@ type CacheMemory struct { //获取Cache键只能为string类型 func (this *CacheMemory) get(key string) interface{} { this.Error.SetError(nil) + if this.Map == nil { + this.Map = Map{} + } + if this.Map[key] == nil { return nil } @@ -23,7 +27,7 @@ func (this *CacheMemory) get(key string) interface{} { if this.GetError() != nil { return nil } - //data:=cacheMap[key]; + if data.time < time.Now().Unix() { delete(this.Map, key) return nil @@ -51,7 +55,12 @@ func (this *CacheMemory) refreshMap() { func (this *CacheMemory) set(key string, value interface{}, time int64) { this.Error.SetError(nil) var data cacheData - dd := this.Map.Get(key, &this.Error) + + if this.Map == nil { + this.Map = Map{} + } + + dd := this.Map[key] if dd == nil { data = cacheData{} @@ -62,9 +71,7 @@ func (this *CacheMemory) set(key string, value interface{}, time int64) { data.time = time data.data = value - if this.Map == nil { - this.Map = Map{} - } + this.Map.Put(key, data) } @@ -113,12 +120,12 @@ func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj { } if len(data) == 1 { - if this.Time == 0 { this.Time = Config.GetInt64("cacheShortTime") } tim = tim + this.Time + } if len(data) == 2 { this.Error.SetError(nil) diff --git a/db.go b/db.go index 84c4f85..012831a 100644 --- a/db.go +++ b/db.go @@ -627,6 +627,21 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) { where += "`" + k + "` LIKE ? " v = "%" + ObjToStr(v) + "%" res = append(res, v) + case "[!~]"://左边任意 + k = strings.Replace(k, "[~]", "", -1) + where += "`" + k + "` LIKE ? " + v = "%" + ObjToStr(v) + res = append(res, v) + case "[!~]"://右边任意 + k = strings.Replace(k, "[~]", "", -1) + where += "`" + k + "` LIKE ? " + v = ObjToStr(v) +"%" + res = append(res, v) + case "[~~]"://手动任意 + k = strings.Replace(k, "[~]", "", -1) + where += "`" + k + "` LIKE ? " + //v = ObjToStr(v) + res = append(res, v) default: def = true @@ -706,8 +721,14 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) { //res=append(res,(v.(Slice))[i]) } } else { - where += "`" + k + "`=? " - res = append(res, v) + if v!=nil{ + where += "`" + k + "`=? " + res = append(res, v) + }else{ + where += "`" + k + "` IS NULL" + //res = append(res, v) + } + } } @@ -741,8 +762,13 @@ func (this *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa //res=append(res,(v.(Slice))[i]) } } else { - where += "`" + k + "` !=? " - res = append(res, v) + if v!=nil{ + where += "`" + k + "` !=? " + res = append(res, v) + }else{ + where += "`" + k + "` IS NOT NULL " + } + } return where, res