缓存框架 - go-cache
go-cache 是 Go 语言实现的一个内存中的缓存框架,实现 Key-Value 的序列存储。
示例代码:
import "github.com/pmylund/go-cache" // Create a cache with a default expiration time of 5 minutes, and which // purges expired items every 30 seconds c := cache.New(5*time.Minute, 30*time.Second) // Set the value of the key "foo" to "bar", with the default expiration time c.Set("foo", "bar", 0) // Set the value of the key "baz" to "yes", with no expiration time // (the item won't be removed until it is re-set, or removed using // c.Delete("baz") c.Set("baz", "yes", -1) // Get the string associated with the key "foo" from the cache foo, found := c.Get("foo") if found { fmt.Println(foo) }
本文由用户 openkk 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!