Documentation
¶
Index ¶
- type Option
- type Reaper
- type TTLMap
- func (m *TTLMap[K, V]) CleanNow()
- func (m *TTLMap[K, V]) Delete(key K)
- func (m *TTLMap[K, V]) Load(key K) (value V, ok bool)
- func (m *TTLMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *TTLMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *TTLMap[K, V]) Range(f func(key K, value V) bool)
- func (m *TTLMap[K, V]) Store(key K, value V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
func WithExpirationCallback ¶
func WithExpirationCallback[K comparable, V any](f func(key K, value V)) Option[K, V]
type Reaper ¶
type Reaper struct {
// contains filtered or unexported fields
}
Reaper regularly expunges expired entries from a TTLMap
func NewReaper ¶
func NewReaper[K comparable, V any](m *TTLMap[K, V]) *Reaper
NewReaper creates a new Reaper that will clean the map with a reasonable default interval.
func NewReaperWithInterval ¶
NewReaperWithInterval creates a new Reaper that will clean the map with a custom interval.
type TTLMap ¶
type TTLMap[K, V any] struct { // contains filtered or unexported fields }
TTLMap provides a thread-safe map which eventually deletes its entries after timeout, as long as there are occasional writes to the map. Its semantics are otherwise identical to sync.Map. A TTLMap must not be copied after first use. When writes are very seldom, then Reaper may be used for periodic cleanup.
func (*TTLMap[K, V]) CleanNow ¶
func (m *TTLMap[K, V]) CleanNow()
CleanNow synchronously cleans up most expired entries. Entries that are inserted and expire while CleanNow is running may be skipped. If a concurrent CleanNow is already running, CleanNow returns immediately without performing any work.