1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package cache
- import (
- "sync"
- "github.com/dmitriygnatenko/internal/interfaces"
- )
- type cache struct {
- data map[string]interface{}
- sync.RWMutex
- }
- func Init() interfaces.ICache {
- return &cache{
- data: make(map[string]interface{}),
- }
- }
- 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{})
- }
|