func (c *Cache) deliverEvents() {
  for e := range c.events {
    for _, listener := range c.listeners {
      listener.C <- e
    }
  }
}
distributes cache events to all registered listeners
package cache
import "github.com/dotStart/Stockpile/entity"
type Listener struct {
  cache *Cache
  C     chan *entity.Event
}
func (e *Listener) Close() {
  e.cache.removeListener(e)
}
func (c *Cache) NewListener() *Listener {
  c.listenerMutex.Lock()
  defer c.listenerMutex.Unlock()
  listener := &Listener{
    cache: c,
    C:     make(chan *entity.Event),
  }
  c.listeners = append(c.listeners, listener)
  return listener
}
func (c *Cache) removeListener(listener *Listener) {
  c.listenerMutex.Lock()
  defer c.listenerMutex.Unlock()
  for i, l := range c.listeners {
    if l == listener {
      c.listeners = append(c.listeners[:i], c.listeners[i+1:]...)
      break
    }
  }
}