3 changed files with 61 additions and 2 deletions
@ -0,0 +1,34 @@ |
|||
package govue |
|||
|
|||
import ( |
|||
"sync" |
|||
"time" |
|||
) |
|||
|
|||
var cache sync.Map |
|||
|
|||
type mcache struct { |
|||
html string |
|||
creation int64 |
|||
timeoutSec int64 |
|||
} |
|||
|
|||
func GetCache(key string) string { |
|||
v, _ := cache.Load(key) |
|||
if v != nil { |
|||
mc := v.(*mcache) |
|||
if time.Now().Unix() < mc.creation+mc.timeoutSec { |
|||
//log.Println("加载缓存")
|
|||
return mc.html |
|||
} |
|||
} |
|||
return "" |
|||
} |
|||
|
|||
func SetCache(key string, val string, timeoutSec int64) { |
|||
cache.Store(key, &mcache{ |
|||
html: val, |
|||
creation: time.Now().Unix(), |
|||
timeoutSec: timeoutSec, |
|||
}) |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue