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