Documentation
¶
Index ¶
- Variables
- type KeyStore
- func (ks *KeyStore[T]) Clean()
- func (ks *KeyStore[T]) Delete(key string)
- func (ks *KeyStore[T]) Get(key string) (*T, error)
- func (ks *KeyStore[T]) Keys() iter.Seq[string]
- func (ks *KeyStore[T]) Set(key string, value T, duration time.Duration)
- func (ks *KeyStore[T]) StartCleanup(cleanupInterval time.Duration)
- func (ks *KeyStore[T]) StopCleanup()
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = errors.New("entry was not found") ErrExpired = errors.New("entry is expired") )
Functions ¶
This section is empty.
Types ¶
type KeyStore ¶
type KeyStore[T any] struct { // contains filtered or unexported fields }
KeyStore is the main structure of this module
func New ¶
New creates a new keystore with an optional goroutine to automatically clean expired values
func (*KeyStore[T]) Clean ¶
func (ks *KeyStore[T]) Clean()
Clean deletes all expired keys from the keystore.
func (*KeyStore[T]) Get ¶
Get returns the value for the given key if it exists and it's not expired.
func (*KeyStore[T]) Set ¶
Set saves a key-value pair with a given expiration. If duration <= 0, the entry will never expire.
func (*KeyStore[T]) StartCleanup ¶
StartCleanup starts a goroutine that periodically deletes all expired keys from the keystore.
func (*KeyStore[T]) StopCleanup ¶
func (ks *KeyStore[T]) StopCleanup()
StopCleanup stops the cleanup goroutine.
Click to show internal directories.
Click to hide internal directories.