finclip-app-manager/infrastructure/cache/mem/mem.go

34 lines
499 B
Go
Raw Permalink Normal View History

2023-10-31 14:07:26 +08:00
package mem
import (
"time"
"github.com/bluele/gcache"
)
//如果不够用修改100000
var memCache gcache.Cache = gcache.New(100000).LRU().Build()
type MemCache struct {
c gcache.Cache
}
func NewMemCache() *MemCache {
return &MemCache{
c: memCache,
}
}
func (m *MemCache) Set(k string, v interface{}, d time.Duration) {
m.c.SetWithExpire(k, v, d)
}
func (m *MemCache) Get(k string) (interface{}, bool) {
v, err := m.c.Get(k)
if err == nil {
return v, true
}
return v, false
}