缓存驱动更换成功,支持3级缓存,memory,以及db
This commit is contained in:
+10
-25
@@ -32,10 +32,8 @@ type Application struct {
|
||||
configPath string
|
||||
Config Map
|
||||
Db HoTimeDB
|
||||
*HoTimeCache
|
||||
*http.Server
|
||||
CacheIns
|
||||
sessionLong CacheIns
|
||||
sessionShort CacheIns
|
||||
http.Handler
|
||||
}
|
||||
|
||||
@@ -51,8 +49,8 @@ func (that *Application) Run(router Router) {
|
||||
}
|
||||
|
||||
//防止手动设置缓存误伤
|
||||
if that.CacheIns == nil {
|
||||
that.SetCache(CacheIns(&CacheMemory{}))
|
||||
if that.HoTimeCache == nil {
|
||||
that.SetCache()
|
||||
}
|
||||
|
||||
//防止手动设置session误伤
|
||||
@@ -103,10 +101,6 @@ func (that *Application) Run(router Router) {
|
||||
that.Db.SetConnect(that.connectDbFunc)
|
||||
}
|
||||
|
||||
if that.CacheIns == nil {
|
||||
that.CacheIns = CacheIns(&CacheMemory{Map: Map{}, Time: that.Config.GetInt64("cacheShortTime")})
|
||||
}
|
||||
|
||||
//异常处理
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
@@ -170,13 +164,6 @@ func (that *Application) SetConnectDB(connect func(err ...*Error) (master, slave
|
||||
|
||||
}
|
||||
|
||||
// SetSession 设置配置文件路径全路径或者相对路径
|
||||
func (that *Application) SetSession(short CacheIns, Long CacheIns) {
|
||||
that.sessionLong = Long
|
||||
that.sessionShort = short
|
||||
|
||||
}
|
||||
|
||||
// SetDefault 默认配置缓存和session实现
|
||||
func (that *Application) SetDefault(connect func(err ...*Error) (*sql.DB, *sql.DB)) {
|
||||
that.SetConfig()
|
||||
@@ -189,10 +176,10 @@ func (that *Application) SetDefault(connect func(err ...*Error) (*sql.DB, *sql.D
|
||||
}
|
||||
|
||||
// SetCache 设置配置文件路径全路径或者相对路径
|
||||
func (that *Application) SetCache(cache CacheIns) {
|
||||
|
||||
that.CacheIns = cache
|
||||
|
||||
func (that *Application) SetCache() {
|
||||
cacheIns := HoTimeCache{}
|
||||
cacheIns.Init(that.Config.GetMap("cache"), HoTimeDBInterface(&that.Db), &that.Error)
|
||||
that.HoTimeCache = &cacheIns
|
||||
}
|
||||
|
||||
// SetConfig 设置配置文件路径全路径或者相对路径
|
||||
@@ -320,11 +307,9 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
//访问实例
|
||||
context := Context{SessionIns: SessionIns{SessionId: sessionId,
|
||||
LongCache: that.sessionLong,
|
||||
ShortCache: that.sessionShort,
|
||||
HoTimeCache: that.HoTimeCache,
|
||||
},
|
||||
CacheIns: that.CacheIns,
|
||||
Resp: w, Req: req, Application: that, RouterString: s, Config: that.Config, Db: &that.Db, HandlerStr: unescapeUrl}
|
||||
Resp: w, Req: req, Application: that, RouterString: s, Config: that.Config, Db: &that.Db, HandlerStr: unescapeUrl}
|
||||
//header默认设置
|
||||
header := w.Header()
|
||||
header.Set("Content-Type", "text/html; charset=utf-8")
|
||||
@@ -470,7 +455,7 @@ func Init(config string) Application {
|
||||
appIns.SetConfig(config)
|
||||
|
||||
SetDB(&appIns)
|
||||
//appIns.SetCache()
|
||||
appIns.SetCache()
|
||||
return appIns
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user