package service import ( "sync" "time" ) const ( cacheExpiration = 5 * time.Minute ) type cache struct { mu sync.RWMutex cache map[string][]string expiration time.Duration } func (c *cache) Get(key string) (val []string) { c.mu.RLock() defer c.mu.RUnlock() return c.cache[key] } func (c *cache) Insert(key string, val []string) { c.mu.Lock() c.cache[key] = val c.mu.Unlock() go func() { time.Sleep(c.expiration) c.Delete(key) }() } func (c *cache) Delete(key string) { c.mu.Lock() defer c.mu.Unlock() delete(c.cache, key) }