34 lines
499 B
Go
34 lines
499 B
Go
|
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
|
||
|
}
|