Feat: cache in-memory store

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

No files matched your search

+26
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)
}