缓存测试成功
This commit is contained in:
parent
1101937028
commit
339302956a
@ -180,6 +180,7 @@ func (that *Application) SetCache() {
|
||||
cacheIns := HoTimeCache{}
|
||||
cacheIns.Init(that.Config.GetMap("cache"), HoTimeDBInterface(&that.Db), &that.Error)
|
||||
that.HoTimeCache = &cacheIns
|
||||
that.Db.HoTimeCache = &cacheIns
|
||||
}
|
||||
|
||||
// SetConfig 设置配置文件路径全路径或者相对路径
|
||||
|
38
cache/cache.go
vendored
38
cache/cache.go
vendored
@ -20,7 +20,7 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
||||
if len(data) == 0 {
|
||||
//内存缓存有
|
||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||
reData = that.memoryCache.Cache(key, data)
|
||||
reData = that.memoryCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
return reData
|
||||
}
|
||||
@ -28,7 +28,7 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
||||
|
||||
//redis缓存有
|
||||
if that.redisCache != nil && that.redisCache.SessionSet {
|
||||
reData = that.redisCache.Cache(key, data)
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
@ -39,7 +39,7 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
||||
|
||||
//db缓存有
|
||||
if that.dbCache != nil && that.dbCache.SessionSet {
|
||||
reData = that.dbCache.Cache(key, data)
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
@ -57,15 +57,15 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
||||
//设置缓存
|
||||
//设置内存缓存
|
||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||
reData = that.memoryCache.Cache(key, data)
|
||||
reData = that.memoryCache.Cache(key, data...)
|
||||
}
|
||||
//redis缓存有
|
||||
if that.redisCache != nil && that.redisCache.SessionSet {
|
||||
reData = that.redisCache.Cache(key, data)
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
}
|
||||
//redis缓存有
|
||||
if that.dbCache != nil && that.dbCache.SessionSet {
|
||||
reData = that.dbCache.Cache(key, data)
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
}
|
||||
return reData
|
||||
|
||||
@ -75,7 +75,7 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
||||
if len(data) == 0 {
|
||||
//内存缓存有
|
||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||
reData = that.memoryCache.Cache(key, data)
|
||||
reData = that.memoryCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
return reData
|
||||
}
|
||||
@ -83,7 +83,7 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
||||
|
||||
//redis缓存有
|
||||
if that.redisCache != nil && that.redisCache.DbSet {
|
||||
reData = that.redisCache.Cache(key, data)
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
@ -94,7 +94,7 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
||||
|
||||
//redis缓存有
|
||||
if that.dbCache != nil && that.dbCache.DbSet {
|
||||
reData = that.dbCache.Cache(key, data)
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
@ -113,15 +113,15 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
||||
//设置缓存
|
||||
//设置内存缓存
|
||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||
reData = that.memoryCache.Cache(key, data)
|
||||
reData = that.memoryCache.Cache(key, data...)
|
||||
}
|
||||
//redis缓存有
|
||||
if that.redisCache != nil && that.redisCache.DbSet {
|
||||
reData = that.redisCache.Cache(key, data)
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
}
|
||||
//redis缓存有
|
||||
if that.dbCache != nil && that.dbCache.DbSet {
|
||||
reData = that.dbCache.Cache(key, data)
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
}
|
||||
return reData
|
||||
}
|
||||
@ -131,7 +131,7 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
|
||||
if len(data) == 0 {
|
||||
//内存缓存有
|
||||
if that.memoryCache != nil {
|
||||
reData = that.memoryCache.Cache(key, data)
|
||||
reData = that.memoryCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
return reData
|
||||
}
|
||||
@ -139,7 +139,7 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
|
||||
|
||||
//redis缓存有
|
||||
if that.redisCache != nil {
|
||||
reData = that.redisCache.Cache(key, data)
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
|
||||
if that.memoryCache != nil {
|
||||
@ -151,7 +151,7 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
|
||||
|
||||
//redis缓存有
|
||||
if that.dbCache != nil {
|
||||
reData = that.dbCache.Cache(key, data)
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if that.memoryCache != nil {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
@ -168,15 +168,15 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
|
||||
//设置缓存
|
||||
//设置内存缓存
|
||||
if that.memoryCache != nil {
|
||||
reData = that.memoryCache.Cache(key, data)
|
||||
reData = that.memoryCache.Cache(key, data...)
|
||||
}
|
||||
//redis缓存有
|
||||
if that.redisCache != nil {
|
||||
reData = that.redisCache.Cache(key, data)
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
}
|
||||
//redis缓存有
|
||||
if that.dbCache != nil {
|
||||
reData = that.dbCache.Cache(key, data)
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
}
|
||||
return reData
|
||||
}
|
||||
@ -237,7 +237,7 @@ func (that *HoTimeCache) Init(config Map, hotimeDb HoTimeDBInterface, err ...*Er
|
||||
}
|
||||
|
||||
if redis.Get("timeout") == nil {
|
||||
redis["timeout"] = 60 * 60 * 24 * 30
|
||||
redis["timeout"] = 60 * 60 * 24 * 15
|
||||
}
|
||||
that.Config["redis"] = redis
|
||||
that.redisCache = &CacheRedis{TimeOut: redis.GetCeilInt64("timeout"),
|
||||
|
5
cache/cache_db.go
vendored
5
cache/cache_db.go
vendored
@ -23,7 +23,6 @@ type CacheDb struct {
|
||||
TimeOut int64
|
||||
DbSet bool
|
||||
SessionSet bool
|
||||
Time int64
|
||||
Db HoTimeDBInterface
|
||||
*Error
|
||||
ContextBase
|
||||
@ -152,10 +151,10 @@ func (that *CacheDb) Cache(key string, data ...interface{}) *Obj {
|
||||
}
|
||||
|
||||
if len(data) == 1 {
|
||||
if that.Time == 0 {
|
||||
if that.TimeOut == 0 {
|
||||
//that.Time = Config.GetInt64("cacheLongTime")
|
||||
}
|
||||
tim += that.Time
|
||||
tim += that.TimeOut
|
||||
}
|
||||
if len(data) == 2 {
|
||||
that.SetError(nil)
|
||||
|
3
cache/cache_redis.go
vendored
3
cache/cache_redis.go
vendored
@ -48,12 +48,15 @@ func (this *CacheRedis) reCon() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if this.Pwd != "" {
|
||||
_, err = this.conn.Do("AUTH", this.Pwd)
|
||||
if err != nil {
|
||||
this.conn = nil
|
||||
this.Error.SetError(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
func (this *CacheRedis) del(key string) {
|
||||
|
10
db/db.go
10
db/db.go
@ -467,7 +467,7 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
qs = append(qs, resWhere...)
|
||||
md5 := that.md5(query, qs...)
|
||||
|
||||
if that.HoTimeCache != nil {
|
||||
if that.HoTimeCache != nil && table != "cached" {
|
||||
//如果缓存有则从缓存取
|
||||
cacheData := that.HoTimeCache.Db(table + ":" + md5)
|
||||
|
||||
@ -484,7 +484,7 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
}
|
||||
|
||||
//缓存
|
||||
if that.HoTimeCache != nil {
|
||||
if that.HoTimeCache != nil && table != "cached" {
|
||||
|
||||
_ = that.HoTimeCache.Db(table+":"+md5, res)
|
||||
}
|
||||
@ -888,7 +888,7 @@ func (that *HoTimeDB) Update(table string, data Map, where Map) int64 {
|
||||
|
||||
//如果更新成功,则删除缓存
|
||||
if rows != 0 {
|
||||
if that.HoTimeCache != nil {
|
||||
if that.HoTimeCache != nil && table != "cached" {
|
||||
_ = that.HoTimeCache.Db(table+"*", nil)
|
||||
}
|
||||
}
|
||||
@ -911,7 +911,7 @@ func (that *HoTimeDB) Delete(table string, data map[string]interface{}) int64 {
|
||||
|
||||
//如果删除成功,删除对应缓存
|
||||
if rows != 0 {
|
||||
if that.HoTimeCache != nil {
|
||||
if that.HoTimeCache != nil && table != "cached" {
|
||||
_ = that.HoTimeCache.Db(table+"*", nil)
|
||||
}
|
||||
}
|
||||
@ -953,7 +953,7 @@ func (that *HoTimeDB) Insert(table string, data map[string]interface{}) int64 {
|
||||
|
||||
//如果插入成功,删除缓存
|
||||
if id != 0 {
|
||||
if that.HoTimeCache != nil {
|
||||
if that.HoTimeCache != nil && table != "cached" {
|
||||
_ = that.HoTimeCache.Db(table+"*", nil)
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,11 @@ func main() {
|
||||
"app": hotime.Proj{
|
||||
"index": hotime.Ctr{
|
||||
"test": func(this *hotime.Context) {
|
||||
fmt.Println(this.Session("test").Data)
|
||||
this.Session("test", 145484978484)
|
||||
fmt.Println(this.Session("test").Data)
|
||||
data := this.Db.Get("cached", "*")
|
||||
fmt.Println(data)
|
||||
fmt.Println(this.Session("test").ToCeilInt())
|
||||
this.Session("test1", 98984984)
|
||||
fmt.Println(this.Session("test1").Data)
|
||||
//fmt.Println(this.Db.GetTag())
|
||||
//this.Application.Log.Error("dasdasdas")
|
||||
//this.Log.Error("dadasdasd")
|
||||
|
Loading…
Reference in New Issue
Block a user