在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
github.com/patrickmn/go-cache package main import ( "log" "time" "github.com/patrickmn/go-cache" ) func main(){ c := cache.New(30*time.Second, 10*time.Second) c.Set("Title", "Spring Festival", cache.DefaultExpiration) value, found := c.Get("Title") if found { log.Println("found:", value) } else { log.Println("not found") } time.Sleep(60*time.Second) log.Println("sleep 60s...") value, found = c.Get("Title") if found { log.Println("found:", value) } else { log.Println("not found") } } output2019/07/08 20:21:13 found: Spring Festival 2019/07/08 20:22:13 sleep 60s... 2019/07/08 20:22:13 not found
定期清除缓存中的过期key,是通过一个常驻goroutine实现的。
|
请发表评论