缓存驱动更换成功,支持3级缓存,memory,以及db

This commit is contained in:
hoteas
2021-05-28 22:52:22 +08:00
parent fc315064e7
commit 1101937028
11 changed files with 369 additions and 126 deletions
+11 -9
View File
@@ -2,7 +2,6 @@ package main
import (
"../../hotime"
"../../hotime/cache"
"fmt"
"golang.org/x/net/websocket"
"time"
@@ -22,18 +21,18 @@ func main() {
//手动模式,
//appIns.SetConfig("example/config/config.json")
//redis缓存接入
ca := cache.CacheIns(&cache.CacheRedis{Host: appIns.Config.GetString("redisHost"), Pwd: appIns.Config.GetString("redisPwd"), Time: appIns.Config.GetCeilInt64("cacheLongTime")})
ca.Cache("xyzm", "dasdas")
ca.Cache("xyzn", "dasdas")
ca.Cache("xyzo", "dasdas")
ca.Cache("xyz*", nil)
//ca := cache.CacheIns(&cache.CacheRedis{Host: appIns.Config.GetString("redisHost"), Pwd: appIns.Config.GetString("redisPwd"), Time: appIns.Config.GetCeilInt64("cacheLongTime")})
//ca.Cache("xyzm", "dasdas")
//ca.Cache("xyzn", "dasdas")
//ca.Cache("xyzo", "dasdas")
//ca.Cache("xyz*", nil)
//fmt.Println(ca.Cache("xyzm").Data)
//mysql
//mysql.SetDB(&appIns)
//自动选择数据库
dbInterface := cache.HoTimeDBInterface(&appIns.Db)
appIns.SetSession(cache.CacheIns(&cache.CacheMemory{}), cache.CacheIns(&cache.CacheDb{Db: dbInterface, Time: appIns.Config.GetInt64("cacheTime")}))
appIns.SetCache(cache.CacheIns(&cache.CacheMemory{}))
//dbInterface := cache.HoTimeDBInterface(&appIns.Db)
//appIns.SetSession(cache.CacheIns(&cache.CacheMemory{}), cache.CacheIns(&cache.CacheDb{Db: dbInterface, Time: appIns.Config.GetInt64("cacheTime")}))
//appIns.SetCache(cache.CacheIns(&cache.CacheMemory{}))
//快捷模式
//appIns.SetDefault(func(err ...*common.Error) (*sql.DB, *sql.DB) {
@@ -50,6 +49,9 @@ 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)
//fmt.Println(this.Db.GetTag())
//this.Application.Log.Error("dasdasdas")
//this.Log.Error("dadasdasd")