gf/geg/os/gcache/usage_basic.go
2018-12-04 19:50:24 +08:00

29 lines
559 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"gitee.com/johng/gf/g/os/gcache"
)
func main() {
// 创建一个缓存对象当然也可以直接使用gcache包方法
c := gcache.New()
// 设置缓存,不过期
c.Set("k1", "v1", 0)
// 获取缓存
fmt.Println(c.Get("k1"))
// 获取缓存大小
fmt.Println(c.Size())
// 缓存中是否存在指定键名
fmt.Println(c.Contains("k1"))
// 删除并返回被删除的键值
fmt.Println(c.Remove("k1"))
// 关闭缓存对象让GC回收资源
c.Close()
}