Feat: cache in-memory store

This commit is contained in:
HFO4
2019-12-05 17:01:14 +08:00
parent 5d50e7ed1e
commit 7375cc01f1
8 changed files with 134 additions and 26 deletions

26
pkg/cache/memo.go vendored Normal file
View File

@@ -0,0 +1,26 @@
package cache
import "sync"
// MemoStore 内存存储驱动
type MemoStore struct {
Store *sync.Map
}
// NewMemoStore 新建内存存储
func NewMemoStore() *MemoStore {
return &MemoStore{
Store: &sync.Map{},
}
}
// Set 存储值
func (store *MemoStore) Set(key string, value interface{}) error {
store.Store.Store(key, value)
return nil
}
// Get 取值
func (store *MemoStore) Get(key string) (interface{}, bool) {
return store.Store.Load(key)
}