缓存驱动更换成功,支持3级缓存,memory,以及db
This commit is contained in:
@@ -16,9 +16,8 @@ import (
|
||||
type HoTimeDB struct {
|
||||
*sql.DB
|
||||
ContextBase
|
||||
cache.CacheIns
|
||||
*cache.HoTimeCache
|
||||
Type string
|
||||
DBCached bool
|
||||
LastQuery string
|
||||
LastData []interface{}
|
||||
ConnectFunc func(err ...*Error) (*sql.DB, *sql.DB)
|
||||
@@ -42,7 +41,7 @@ func (that *HoTimeDB) GetType() string {
|
||||
|
||||
// Action 事务,如果action返回true则执行成功;false则回滚
|
||||
func (that *HoTimeDB) Action(action func(db HoTimeDB) bool) bool {
|
||||
db := HoTimeDB{DB: that.DB, CacheIns: that.CacheIns, DBCached: that.DBCached}
|
||||
db := HoTimeDB{DB: that.DB, HoTimeCache: that.HoTimeCache}
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
that.LastErr.SetError(err)
|
||||
@@ -468,9 +467,9 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
qs = append(qs, resWhere...)
|
||||
md5 := that.md5(query, qs...)
|
||||
|
||||
if that.DBCached && that.CacheIns != nil {
|
||||
if that.HoTimeCache != nil {
|
||||
//如果缓存有则从缓存取
|
||||
cacheData := that.Cache(table + ":" + md5)
|
||||
cacheData := that.HoTimeCache.Db(table + ":" + md5)
|
||||
|
||||
if cacheData.Data != nil {
|
||||
return cacheData.ToMapArray()
|
||||
@@ -485,9 +484,9 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
}
|
||||
|
||||
//缓存
|
||||
if that.DBCached && that.CacheIns != nil {
|
||||
if that.HoTimeCache != nil {
|
||||
|
||||
_ = that.Cache(table+":"+md5, res)
|
||||
_ = that.HoTimeCache.Db(table+":"+md5, res)
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -889,8 +888,8 @@ func (that *HoTimeDB) Update(table string, data Map, where Map) int64 {
|
||||
|
||||
//如果更新成功,则删除缓存
|
||||
if rows != 0 {
|
||||
if that.DBCached && that.CacheIns != nil {
|
||||
_ = that.Cache(table+"*", nil)
|
||||
if that.HoTimeCache != nil {
|
||||
_ = that.HoTimeCache.Db(table+"*", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -912,8 +911,8 @@ func (that *HoTimeDB) Delete(table string, data map[string]interface{}) int64 {
|
||||
|
||||
//如果删除成功,删除对应缓存
|
||||
if rows != 0 {
|
||||
if that.DBCached && that.CacheIns != nil {
|
||||
_ = that.Cache(table+"*", nil)
|
||||
if that.HoTimeCache != nil {
|
||||
_ = that.HoTimeCache.Db(table+"*", nil)
|
||||
}
|
||||
}
|
||||
//return 0
|
||||
@@ -954,8 +953,8 @@ func (that *HoTimeDB) Insert(table string, data map[string]interface{}) int64 {
|
||||
|
||||
//如果插入成功,删除缓存
|
||||
if id != 0 {
|
||||
if that.DBCached && that.CacheIns != nil {
|
||||
_ = that.Cache(table+"*", nil)
|
||||
if that.HoTimeCache != nil {
|
||||
_ = that.HoTimeCache.Db(table+"*", nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user