微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

go-cache Go 语言的缓存框架

程序名称:go-cache

授权协议: MIT

操作系统: 跨平台

开发语言: Google Go

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

go-cache 官网

https://github.com/patrickmn/go-cache

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐