package cache //go:generate mkdir -p mocks //go:generate rm -rf ./mocks/*_minimock.go //go:generate minimock -i ../../interfaces.Cache -o ./mocks/ -s "_minimock.go" import ( "sync" "github.com/dmitriygnatenko/internal/interfaces" ) type cache struct { data map[string]interface{} sync.RWMutex } func Init() (interfaces.Cache, error) { return &cache{ data: make(map[string]interface{}), }, nil } func (c *cache) Get(key string) (interface{}, bool) { c.RLock() defer c.RUnlock() res, found := c.data[key] if !found { return nil, false } return res, true } func (c *cache) Set(key string, value interface{}) { c.Lock() defer c.Unlock() c.data[key] = value } func (c *cache) FlushAll() { c.Lock() defer c.Unlock() c.data = make(map[string]interface{}) }