緩存框架 - 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 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!