You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gocache/go.go

35 lines
868 B

package gocache
import (
"github.com/patrickmn/go-cache"
"time"
)
// Go https://github.com/patrickmn/go-cache
type Go struct {
goCache *cache.Cache // 驱动
expiration time.Duration // 默认过期时间
clear time.Duration // 清理过期数据
}
// NewGo 实例化
func NewGo(expiration, clear time.Duration) *Go {
c := cache.New(expiration, clear)
return &Go{goCache: c, expiration: expiration, clear: clear}
}
// Get 获取单个数据
func (g *Go) Get(key string) (interface{}, bool) {
return g.goCache.Get(key)
}
// Set 插入数据 并设置过期时间
func (g *Go) Set(key string, value interface{}, expirationTime time.Duration) {
g.goCache.Set(key, value, expirationTime)
}
// SetDefault 插入数据 并设置为默认过期时间
func (g *Go) SetDefault(key string, value interface{}) {
g.goCache.Set(key, value, g.expiration)
}