memory

package
v0.0.0-...-fdc8e6b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2022 License: Unlicense Imports: 6 Imported by: 0

Documentation

Overview

memory is a thread safe library for handling TTL of keys as an expiry solution, `memory` is only suitable of in-memory store as the exoiry records do not persist

Index

Constants

View Source
const COMPACTOR_INTERVAL = 5 * time.Second

Duration between times when we clear out all old data from the memory cache.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryExpiry

type MemoryExpiry struct {
	*expiry.Expiry
	// contains filtered or unexported fields
}

Handles tracking of expiration times.

func NewMemoryExpiry

func NewMemoryExpiry(removeFunc func(key string) error) (*MemoryExpiry, error)

NewMemoryExoury takes a `removeFunc` which is the function that will be called when an expiry takes place

func (*MemoryExpiry) AddExpiry

func (m *MemoryExpiry) AddExpiry(key string, ttl time.Duration)

Adds a key and associated TTL to the expiry records. A TTL here can be 0 (no expiry) - though it will _not_ be added to the Expiry records

func (*MemoryExpiry) Compact

func (m *MemoryExpiry) Compact() []string

Returns all keys that have expired, removing them from the expiry's records afterwards.

func (*MemoryExpiry) GetExpiry

func (m *MemoryExpiry) GetExpiry(key string) time.Time

GetExpiry grabs the Expiry value for a given key A "Zero" time is returned if the key is not in the Expiry records

func (*MemoryExpiry) GetTTL

func (m *MemoryExpiry) GetTTL(key string) (time.Duration, error)

GetTTL grabs the TTL of the key (always >=1s), or 0 if no expiry/not found An error is returned if the key does not exist in the expiry records (no expiry/not found)

func (*MemoryExpiry) Len

func (m *MemoryExpiry) Len() uint

func (*MemoryExpiry) RemoveExpired

func (m *MemoryExpiry) RemoveExpired()

func (*MemoryExpiry) RemoveExpiry

func (m *MemoryExpiry) RemoveExpiry(key interface{}, _ interface{})

RemoveExpiry allows the storage backend to tell us it removed a key and we can stop tracking it This is crucial if the store has performed an eviction to avoid the expiry records needlessly growing/leaking memory

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL