Documentation
¶
Overview ¶
Package ttlmap provides a map-like interface with string keys and expirable items. Keys are currently limited to strings.
Index ¶
- Variables
- func WithExpiration(expiration time.Time) *time.Time
- func WithTTL(duration time.Duration) *time.Time
- type Item
- type KeyExistMode
- type Map
- func (m *Map) Delete(key string) (Item, error)
- func (m *Map) Drain()
- func (m *Map) Draining() <-chan struct{}
- func (m *Map) Get(key string) (Item, error)
- func (m *Map) Len() int
- func (m *Map) Range(num int) []*Item
- func (m *Map) Set(key string, item Item, opts *SetOptions) error
- func (m *Map) Update(key string, item Item, opts *UpdateOptions) (Item, error)
- type Options
- type SetOptions
- type UpdateOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotExist = errors.New("key does not exist") ErrExist = errors.New("key already exists") ErrDrained = errors.New("map was drained") )
Errors returned Map operations.
Functions ¶
func WithExpiration ¶
WithExpiration creates an expiration time.
Types ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item represents an item with an associated value and optional expiration.
func (*Item) Expiration ¶
Expiration returns the item's expiration time.
type KeyExistMode ¶
type KeyExistMode int
KeyExistMode represents a restriction on the existence of a key for the operation to succeed.
const ( // KeyExistDontCare can be used to ignore wether a key exists or not. KeyExistDontCare KeyExistMode = 0 // KeyExistNotYet fails the operation if the key exists already. KeyExistNotYet KeyExistMode = 1 // KeyExistAlready fails the opration if the key does not exist already. KeyExistAlready KeyExistMode = 2 )
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is the equivalent of a map[string]interface{} but with expirable Items.
func (*Map) Delete ¶
Delete deletes the item with the specified key from the map. ErrNotExist will be returned if the key does not exist. ErrDrained will be returned if the map is already drained.
func (*Map) Drain ¶
func (m *Map) Drain()
Drain evicts all remaining elements from the map and terminates the usage of this map.
func (*Map) Draining ¶
func (m *Map) Draining() <-chan struct{}
Draining returns the channel that is closed when the map starts draining.
func (*Map) Get ¶
Get returns the item in the map with the given key. ErrNotExist will be returned if the key does not exist. ErrDrained will be returned if the map is already drained.
type Options ¶
type Options struct { InitialCapacity int OnWillExpire func(key string, item Item) OnWillEvict func(key string, item Item) }
Options for initializing a new Map.
type SetOptions ¶
type SetOptions struct {
KeyExist KeyExistMode
}
SetOptions for setting items on a Map.
type UpdateOptions ¶
UpdateOptions for updating items on a Map.