gotosocial/vendor/github.com/quasoft/memstore/cache.go
Tobi Smethurst 98263a7de6
Grand test fixup (#138)
* start fixing up tests

* fix up tests + automate with drone

* fiddle with linting

* messing about with drone.yml

* some more fiddling

* hmmm

* add cache

* add vendor directory

* verbose

* ci updates

* update some little things

* update sig
2021-08-12 21:03:24 +02:00

41 lines
592 B
Go

package memstore
import (
"sync"
)
type cache struct {
data map[string]valueType
mutex sync.RWMutex
}
func newCache() *cache {
return &cache{
data: make(map[string]valueType),
}
}
func (c *cache) value(name string) (valueType, bool) {
c.mutex.RLock()
defer c.mutex.RUnlock()
v, ok := c.data[name]
return v, ok
}
func (c *cache) setValue(name string, value valueType) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.data[name] = value
}
func (c *cache) delete(name string) {
c.mutex.Lock()
defer c.mutex.Unlock()
if _, ok := c.data[name]; ok {
delete(c.data, name)
}
}