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
- type MemoryExpiry
- func (m *MemoryExpiry) AddExpiry(key string, ttl time.Duration)
- func (m *MemoryExpiry) Compact() []string
- func (m *MemoryExpiry) GetExpiry(key string) time.Time
- func (m *MemoryExpiry) GetTTL(key string) (time.Duration, error)
- func (m *MemoryExpiry) Len() uint
- func (m *MemoryExpiry) RemoveExpired()
- func (m *MemoryExpiry) RemoveExpiry(key interface{}, _ interface{})
Constants ¶
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 ¶
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