You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
532 B

package govue2
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,
})
}