文档:https://pkg.go.dev/github.com/patrickmn/go-cache
Constants
const (NoExpiration time.Duration = -1 // 不过期DefaultExpiration time.Duration = 0 // 过期时间为cache的过期时间)
type Cache
// 默认defaultExpiration过期,每间隔cleanupInterval开始清理的cachefunc New(defaultExpiration, cleanupInterval time.Duration) *Cache// Add 仅当key不存在时才添加func (c Cache) Add(k string, x interface{}, d time.Duration) error// Set 如果key存在会直接覆盖func (c Cache) Set(k string, x interface{}, d time.Duration)func (c Cache) SetDefault(k string, x interface{})func (c Cache) Decrement // 自减func (c Cache) Increment // 自增func (c Cache) Delete(k string)func (c Cache) DeleteExpired() // 主动清理过期的条目func (c Cache) Flush() // 删除所有func (c Cache) Get(k string) (interface{}, bool)func (c Cache) GetWithExpiration(k string) (interface{}, time.Time, bool)func (c Cache) ItemCount() int // 返回cache中的key数,可能包含过期但未清理的keyfunc (c Cache) Load(r io.Reader) errorfunc (c Cache) LoadFile(fname string) errorfunc (c Cache) Save(w io.Writer) (err error)func (c Cache) SaveFile(fname string) error// 仅当key存在,且没过期才有效func (c Cache) Replace(k string, x interface{}, d time.Duration) error
