diff --git a/.idea/hotime.iml b/.idea/hotime.iml
index 86d29cd..c2f07d0 100644
--- a/.idea/hotime.iml
+++ b/.idea/hotime.iml
@@ -5,6 +5,5 @@
-
\ No newline at end of file
diff --git a/.idea/libraries/Go_SDK.xml b/.idea/libraries/Go_SDK.xml
deleted file mode 100644
index 6552a3b..0000000
--- a/.idea/libraries/Go_SDK.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 220b8c9..a1baa2a 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,20 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -23,112 +35,26 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -145,12 +71,20 @@
Ping
SESSION_TYPE
GetString
+ CacheMemory
+ GetTag
MUTEX_SESSION_TYPE
GetTag
+ CacheRedis
+
+
+
@@ -220,23 +157,42 @@
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -266,7 +222,7 @@
-
+
@@ -291,14 +247,6 @@
-
- project
-
-
-
-
-
-
@@ -363,9 +311,17 @@
false
+
+ project
+
+
+
+
+
+
-
+
@@ -373,23 +329,23 @@
- C:\Users\彭\AppData\Roaming\Subversion
+ C:\Users\92597\AppData\Roaming\Subversion
125
-
-
+
+
-
-
+
+
@@ -430,6 +386,8 @@
+
+
1500458878821
@@ -624,7 +582,7 @@
-
+
@@ -639,27 +597,34 @@
-
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
@@ -682,35 +647,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -758,13 +694,6 @@
-
-
-
-
-
-
-
@@ -779,13 +708,6 @@
-
-
-
-
-
-
-
@@ -800,13 +722,6 @@
-
-
-
-
-
-
-
@@ -870,49 +785,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -920,111 +792,210 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
+
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/application.go b/application.go
index 30997be..07aa2c0 100644
--- a/application.go
+++ b/application.go
@@ -35,6 +35,10 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, req *http.Request) {
//启动实例
func (this *Application) Run(router Router) {
+
+
+
+
this.Router = router
//this.Port = port
this.Port = this.Config.GetString("port")
@@ -175,9 +179,9 @@ func (this *Application) SetConnectListener(lis func(this *Context) bool) {
}
//网络错误
-func (this *Application) session(w http.ResponseWriter, req *http.Request) {
-
-}
+//func (this *Application) session(w http.ResponseWriter, req *http.Request) {
+//
+//}
//序列化链接
func (this *Application) urlSer(url string) (string, []string) {
diff --git a/cache_memory.go b/cache_memory.go
index f7195e6..619d3de 100644
--- a/cache_memory.go
+++ b/cache_memory.go
@@ -2,12 +2,14 @@ package hotime
import (
"time"
+ "sync"
)
type CacheMemory struct {
Time int64
Map
contextBase
+ mutex *sync.RWMutex
}
//获取Cache键只能为string类型
@@ -56,7 +58,13 @@ func (this *CacheMemory) delete(key string) {
func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
- return SafeMutex(MUTEX_MEMORY_CACHE, func() interface{} {
+ if this.mutex==nil{
+ this.mutex=&sync.RWMutex{}
+ }
+
+
+ this.mutex.Lock()
+ defer this.mutex.Unlock()
if len(data) == 0 {
return &Obj{Data: this.get(key)}
@@ -88,6 +96,5 @@ func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
this.set(key, data[0], tim)
return &Obj{Data: nil}
- }).(*Obj)
}
diff --git a/cache_redis.go b/cache_redis.go
new file mode 100644
index 0000000..eef2d13
--- /dev/null
+++ b/cache_redis.go
@@ -0,0 +1,61 @@
+package hotime
+
+import (
+ "time"
+)
+
+type CacheRedis struct {
+ Time int64
+ Map
+ contextBase
+}
+
+//获取Cache键只能为string类型
+func (this *CacheRedis) get(key string) interface{} {
+ this.Error.SetError(nil)
+ if this.Map[key] == nil {
+ return nil
+ }
+ data := this.Map.Get(key, &this.Error).(cacheData)
+ if this.GetError() != nil {
+ return nil
+ }
+ //data:=cacheMap[key];
+ if data.time <= time.Now().Unix() {
+ delete(this.Map, key)
+ return nil
+ }
+ return data.data
+}
+
+//key value ,时间为时间戳
+func (this *CacheRedis) set(key string, value interface{}, time int64) {
+ this.Error.SetError(nil)
+ var data cacheData
+ dd := this.Map.Get(key, &this.Error)
+
+ if dd == nil {
+ data = cacheData{}
+ } else {
+ data = dd.(cacheData)
+ }
+
+ data.time = time
+ data.data = value
+
+ if this.Map == nil {
+ this.Map = Map{}
+ }
+ this.Map.Put(key, data)
+}
+
+func (this *CacheRedis) delete(key string) {
+
+ delete(this.Map, key)
+}
+
+//func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
+//
+//
+//
+//}
diff --git a/const.go b/const.go
index 1b73ae7..bd0d2ed 100644
--- a/const.go
+++ b/const.go
@@ -5,16 +5,5 @@ const (
LOG_NIL = 1
LOG_FILE=2
)
-
-//锁关键字
-const (
- MUTEX_MAP = "HOTIME-MAP"
- MUTEX_SLICE = "HOTIME-SLICE"
- MUTEX_MEMORY_CACHE = "HOTIME-MUTEX-MEMORYCACHE"
- MUTEX_HOTIME_SYSTEM_ERR="HOTIME-SYSTEM-ERR"
-)
-
-//锁关键字
-const (
- MUTEX_SESSION_TYPE = "SESSION-TYPE#"
-)
\ No newline at end of file
+//session储存头
+const HEAD_SESSION_ADD ="session#"
\ No newline at end of file
diff --git a/error.go b/error.go
index c37fae9..a3e170c 100644
--- a/error.go
+++ b/error.go
@@ -1,6 +1,8 @@
package hotime
-import "fmt"
+import (
+ "fmt"
+)
//框架层处理错误
type Error struct {
@@ -15,11 +17,11 @@ func(this *Error)GetError()error{
func(this *Error)SetError(err error,loglevel ...int){
- SafeMutex(MUTEX_HOTIME_SYSTEM_ERR, func() interface{} {
+
this.err=nil
if err==nil{
this.err=err
- return nil
+ return
}
lev:=Config.GetInt("LOG_NIL")
@@ -35,8 +37,5 @@ func(this *Error)SetError(err error,loglevel ...int){
fmt.Println(err)
}
this.err=err
- return nil
- })
-
-
+ return
}
diff --git a/example/config/config.json b/example/config/config.json
index 3d4ee02..14109fc 100644
--- a/example/config/config.json
+++ b/example/config/config.json
@@ -14,5 +14,5 @@
"logLevel": 0,
"port": "80",
"sessionName": "HOTIME",
- "tpt": "tpt"
+ "tpt": "example/tpt"
}
\ No newline at end of file
diff --git a/example/main.go b/example/main.go
index 6a527f3..358cc1f 100644
--- a/example/main.go
+++ b/example/main.go
@@ -10,6 +10,21 @@ import (
func main() {
+ x:=hotime.CacheMemory{}
+ x.Cache("x",123)
+
+ for i:=0;i<10000000 ;i++ {
+ go func() {
+ x.Cache("y",i)
+ fmt.Println(x.Cache("y"))
+ fmt.Println(x.Cache("y",nil))
+
+ }()
+
+ }
+
+
+
appIns := hotime.Application{}
i := 0
@@ -21,7 +36,7 @@ func main() {
})
//手动模式,
- appIns.SetConfig()
+ appIns.SetConfig("example/config/config.json")
appIns.SetConnectDB(func(err ...*hotime.Error) *sql.DB {
query := appIns.Config.GetString("dbUser") + ":" + appIns.Config.GetString("dbPwd") +
"@tcp(" + appIns.Config.GetString("dbHost") + ":" + appIns.Config.GetString("dbPort") + ")/" + appIns.Config.GetString("dbName") + "?charset=utf8"
diff --git a/func.go b/func.go
index 90b7236..7f36bbd 100644
--- a/func.go
+++ b/func.go
@@ -5,25 +5,28 @@ import (
"encoding/hex"
"math"
"strings"
- "sync"
)
+
+
+
//安全锁
-func SafeMutex(tag string, f func() interface{}) interface{} {
+//func SafeMutex(tag int, f func() interface{}) interface{} {
+//
+// mutexer.Lock()
+// if mutex[tag] == nil {
+//
+// mutex[tag] = &sync.RWMutex{}
+//
+// }
+// mutexer.Unlock()
+//
+// mutex[tag].Lock()
+// res := f()
+// mutex[tag].Unlock()
+// return res
+//}
- mutexer.Lock()
- if mutex[tag] == nil {
-
- mutex[tag] = &sync.RWMutex{}
-
- }
- mutexer.Unlock()
-
- mutex[tag].Lock()
- res := f()
- mutex[tag].Unlock()
- return res
-}
//字符串首字符大写
func StrFirstToUpper(str string) string {
diff --git a/map.go b/map.go
index ecbd222..5d02738 100644
--- a/map.go
+++ b/map.go
@@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"reflect"
- "time"
)
//hotime的常用map
@@ -48,17 +47,6 @@ func (this Map) GetInt(key string, err ...*Error) int {
}
-// //唯一标志
-func (this Map) GetTag() int64 {
-
- res := this.GetInt64(MUTEX_MAP)
- if res == int64(0) {
- res = time.Now().UnixNano()
- this.Put(MUTEX_MAP, res)
- }
- return res
-}
-
//获取Int
func (this Map) GetInt64(key string, err ...*Error) int64 {
v := ObjToInt64((this)[key], err...)
diff --git a/session.go b/session.go
index dab8064..58b92cc 100644
--- a/session.go
+++ b/session.go
@@ -12,10 +12,10 @@ type SessionIns struct {
func (this *SessionIns) set() {
if this.ShortCache != nil {
- this.ShortCache.Cache(MUTEX_SESSION_TYPE+this.SessionId, this.Map)
+ this.ShortCache.Cache(this.SessionId, this.Map)
}
if this.LongCache != nil {
- this.LongCache.Cache(MUTEX_SESSION_TYPE+this.SessionId, this.Map)
+ this.LongCache.Cache(this.SessionId, this.Map)
}
}
@@ -44,23 +44,23 @@ func (this *SessionIns) Session(key string, data ...interface{}) *Obj {
func (this *SessionIns) get() {
if this.ShortCache != nil {
- this.Map = this.ShortCache.Cache(MUTEX_SESSION_TYPE + this.SessionId).ToMap()
+ this.Map = this.ShortCache.Cache(HEAD_SESSION_ADD + this.SessionId).ToMap()
if this.Map != nil {
return
}
}
if this.LongCache != nil {
- this.Map = this.LongCache.Cache(MUTEX_SESSION_TYPE + this.SessionId).ToMap()
+ this.Map = this.LongCache.Cache(HEAD_SESSION_ADD + this.SessionId).ToMap()
if this.Map != nil {
if this.ShortCache != nil {
- this.ShortCache.Cache(MUTEX_SESSION_TYPE+this.SessionId, this.Map)
+ this.ShortCache.Cache(HEAD_SESSION_ADD+this.SessionId, this.Map)
}
return
}
}
this.Map = Map{}
- this.ShortCache.Cache(MUTEX_SESSION_TYPE+this.SessionId, this.Map)
+ this.ShortCache.Cache(HEAD_SESSION_ADD+this.SessionId, this.Map)
return
}
diff --git a/var.go b/var.go
index e17e760..5dcac6c 100644
--- a/var.go
+++ b/var.go
@@ -1,14 +1,6 @@
package hotime
-import "sync"
-//var Config = struct {
-// LogLevel int
-//}{
-// LogLevel: LOG_FMT, //日志等级处理,LogFmt,显示所有错误到控制台,LogNil不记录任何错误
-//}
-var mutex = map[interface{}]*sync.RWMutex{} //安全锁
-var mutexer = sync.RWMutex{} //读写锁
var IsRun = false //当前状态
var App = map[string]*Application{} //整个项目