func (r *Registry) Exists(key string) bool {
	_, ok := r.m[key]
	return ok
}
Exists returns true if an item with the given key exists in the registry.
package limiters
import (
	"container/heap"
	"time"
)
type pqItem struct {
	value interface{}
	exp   time.Time
	index int
	key   string
}
type gcPq []*pqItem
func (pq gcPq) Len() int { return len(pq) }
func (pq gcPq) Less(i, j int) bool {
	return pq[i].exp.Before(pq[j].exp)
}
func (pq gcPq) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}
func (pq *gcPq) Push(x interface{}) {
	n := len(*pq)
	item := x.(*pqItem)
	item.index = n
	*pq = append(*pq, item)
}
func (pq *gcPq) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1  
	*pq = old[0 : n-1]
	return item
}
type Registry struct {
	pq *gcPq
	m  map[string]*pqItem
}
func NewRegistry() *Registry {
	pq := make(gcPq, 0)
	return &Registry{pq: &pq, m: make(map[string]*pqItem)}
}
func (r *Registry) GetOrCreate(key string, value func() interface{}, ttl time.Duration, now time.Time) interface{} {
	item, ok := r.m[key]
	if ok {
		item.exp = now.Add(ttl)
		heap.Fix(r.pq, item.index)
	} else {
		item = &pqItem{
			value: value(),
			exp:   now.Add(ttl),
			key:   key,
		}
		heap.Push(r.pq, item)
		r.m[key] = item
	}
	return item.value
}
func (r *Registry) DeleteExpired(now time.Time) int {
	c := 0
	for {
		if len(*r.pq) == 0 {
			break
		}
		item := (*r.pq)[0]
		if now.Before(item.exp) {
			break
		}
		delete(r.m, item.key)
		heap.Pop(r.pq)
		c++
	}
	return c
}
func (r *Registry) Delete(key string) {
	item, ok := r.m[key]
	if !ok {
		return
	}
	delete(r.m, key)
	heap.Remove(r.pq, item.index)
}