improve (lock): leverage RWLock

This commit is contained in:
Mickael Kerjean 2019-05-08 15:16:23 +10:00
parent 1c24026925
commit eeef0f174c

View file

@ -79,7 +79,7 @@ func NewQuickCache(arg ...time.Duration) AppCache {
type KeyValueStore struct { type KeyValueStore struct {
cache map[string]interface{} cache map[string]interface{}
sync.Mutex sync.RWMutex
} }
func NewKeyValueStore() KeyValueStore { func NewKeyValueStore() KeyValueStore {
@ -87,9 +87,9 @@ func NewKeyValueStore() KeyValueStore {
} }
func (this *KeyValueStore) Get(key string) interface{} { func (this *KeyValueStore) Get(key string) interface{} {
this.Lock() this.RLock()
val := this.cache[key] val := this.cache[key]
this.Unlock() this.RUnlock()
return val return val
} }