Documentation ¶
Index ¶
- type TimedMap
- func (tm *TimedMap) Contains(key interface{}) bool
- func (tm *TimedMap) Flush()
- func (tm *TimedMap) GetExpires(key interface{}) (time.Time, error)
- func (tm *TimedMap) GetValue(key interface{}) interface{}
- func (tm *TimedMap) Refresh(key interface{}, d time.Duration) error
- func (tm *TimedMap) Remove(key interface{})
- func (tm *TimedMap) Set(key, value interface{}, expiresAfter time.Duration, ...)
- func (tm *TimedMap) Size() int
- func (tm *TimedMap) StopCleaner()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TimedMap ¶
type TimedMap struct {
// contains filtered or unexported fields
}
TimedMap contains a map with all key-value pairs, and a timer, which cleans the map in the set tick durations from expired keys.
func New ¶
New creates and returns a new instance of TimedMap. The passed cleanupTickTime will be passed to the cleanup Timer, which iterates through the map and deletes expired key-value pairs.
func (*TimedMap) Contains ¶
Contains returns true, if the key exists in the map. false will be returned, if there is no value to the key or if the key-value pair was expired.
func (*TimedMap) GetExpires ¶
GetExpires returns the expire time of a key-value pair. If the key-value pair does not exist in the map or was expired, this will return an error object.
func (*TimedMap) GetValue ¶
func (tm *TimedMap) GetValue(key interface{}) interface{}
GetValue returns an interface of the value of a key in the map. The returned value is nil if there is no value to the passed key or if the value was expired.
func (*TimedMap) Refresh ¶
Refresh extends the expire time for a key-value pair about the passed duration. If there is no value to the key passed, this will return an error object.
func (*TimedMap) Remove ¶
func (tm *TimedMap) Remove(key interface{})
Remove deletes a key-value pair in the map.
func (*TimedMap) Set ¶
func (tm *TimedMap) Set(key, value interface{}, expiresAfter time.Duration, cb ...func(value interface{}))
Set appends a key-value pair to the mao ir sets the value of a key. expiresAfter sets the expire time after the key-value pair will automatically be removed from the map.
func (*TimedMap) StopCleaner ¶
func (tm *TimedMap) StopCleaner()
StopCleaner stops the cleaner go routine and timer. This should always be called after exiting a scope where TimedMap is used that the data can be cleaned up correctly.