// NewExpiring returns an initialized expiring cache. func NewExpiring() *Expiring { … } // NewExpiringWithClock is like NewExpiring but allows passing in a custom // clock for testing. func NewExpiringWithClock(clock clock.Clock) *Expiring { … } type Expiring … type entry … // Get looks up an entry in the cache. func (c *Expiring) Get(key interface{ … } // Set sets a key/value/expiry entry in the map, overwriting any previous entry // with the same key. The entry expires at the given expiry time, but its TTL // may be lengthened or shortened by additional calls to Set(). Garbage // collection of expired entries occurs during calls to Set(), however calls to // Get() will not return expired entries that have not yet been garbage // collected. func (c *Expiring) Set(key interface{ … } // Delete deletes an entry in the map. func (c *Expiring) Delete(key interface{ … } // del deletes the entry for the given key. The generation argument is the // generation of the entry that should be deleted. If the generation has been // changed (e.g. if a set has occurred on an existing element but the old // cleanup still runs), this is a noop. If the generation argument is 0, the // entry's generation is ignored and the entry is deleted. // // del must be called under the write lock. func (c *Expiring) del(key interface{ … } // Len returns the number of items in the cache. func (c *Expiring) Len() int { … } func (c *Expiring) gc(now time.Time) { … } type expiringHeapEntry … type expiringHeap … var _ … func (cq expiringHeap) Len() int { … } func (cq expiringHeap) Less(i, j int) bool { … } func (cq expiringHeap) Swap(i, j int) { … } func (cq *expiringHeap) Push(c interface{ … } func (cq *expiringHeap) Pop() interface{ … }