Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
Value interface{}
// contains filtered or unexported fields
}
Item is an item in TTL list.
type ItemID ¶
type ItemID uint64
ItemID is an unique item id generated by TTL when adding a new item. It is incremented sequentially, no entropy.
const InvalidItemID ItemID = 0
InvalidItemID is an invalid ItemID.
type OnItemTimeout ¶
type OnItemTimeout func(id ItemID, value interface{})
OnItemTimeout is a prototype of a callback function to receive an item timeout notification where id will be the id of the item that timed out and value being the value of that item.
type TTL ¶
type TTL struct {
// contains filtered or unexported fields
}
TTL is a timeout queue that times out added items with a given Time To Live. TTL uses a timer to trim outdated items. Precision is low, always slightly late, a smidgen after item's real timeout, each time.
func New ¶
func New(cb OnItemTimeout) *TTL
New returns a new TTL instance. Optional callback function cb is called when an item times out.
func (*TTL) Add ¶
Add adds specified value to TTL with the specified timeout. Returns an id under which the item was stored.