Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
This section is empty.
Types ¶
type TTL ¶
type TTL struct {
// contains filtered or unexported fields
}
TTL is an opaque structure that stores key/values in an internal map. These values have a time-to-live callback functions associated with them. Depending on configuration either these values are automatically deleted from the map on expiration.
func New ¶
New creates a new TTL map with the provided capacity. If autoDelete is set then the key will be deleted from the map on either the cancel or timeout event.
func (*TTL) Delete ¶
Delete removes the key from the TTL map and aborts the waiting function. It also prevents callbacks from being called. It returns true if the key did expire.
func (*TTL) DeleteByValue ¶
DeleteByValue walks the TTL map and calls delete if the find callback returns true. It returns the number of deletes called.
func (*TTL) Get ¶
Get returns the corresponding value for the provided key. It also returns true if the value was expired.
func (*TTL) Put ¶
func (tm *TTL) Put(pctx context.Context, ttl time.Duration, key any, val any, expired func(context.Context, any, any), remove func(context.Context, any, any))
Put inserts the provided key and value into the TTL map. The ttl values designates the duration of the validity of this key value pair. The expired function is called when the duration expires and the remove callback is called when the key is Canceled.