mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-23 20:26:39 +00:00
98263a7de6
* 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
41 lines
592 B
Go
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)
|
|
}
|
|
}
|