expiry

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: 4 Imported by: 0

Documentation

Overview

Common methods for Expiry packages

Common methods for Expiry packages

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &Options{
	Clock:             realClock{},
	CompactorInterval: time.Duration(5) * time.Minute,
}

Functions

This section is empty.

Types

type Expiry

type Expiry struct {
	Clock clock
	// contains filtered or unexported fields
}

Handles tracking of expiration times. This is intentionally _not_ an interface The way the Expiry packages implement this is unique

func NewExpiry

func NewExpiry(options *Options) (*Expiry, error)

func (*Expiry) IsRunning

func (e *Expiry) IsRunning() bool

IsRunning can access the running state readonly

func (*Expiry) NewExpiryRecordTTL

func (e *Expiry) NewExpiryRecordTTL(key string, ttl time.Duration) ExpiryRecord

func (*Expiry) Start

func (e *Expiry) Start()

func (*Expiry) Stop

func (e *Expiry) Stop()

type ExpiryRecord

type ExpiryRecord struct {
	Key string
	// An unsigned int32 is good until 2100...
	Expiry tinytime.TinyTime
}

ExpiryRecord is an efficient way to encode the Expiry time in a uint32

func NewExpiryRecord

func NewExpiryRecord(key string, expires time.Time) ExpiryRecord

func NewExpiryRecordTTL

func NewExpiryRecordTTL(key string, clock clock, ttl time.Duration) ExpiryRecord

func (ExpiryRecord) HasExpired

func (r ExpiryRecord) HasExpired(now time.Time) bool

HasExpired uses the given time.Time to determine if the key is valid

func (ExpiryRecord) HasExpiry

func (r ExpiryRecord) HasExpiry() bool

HasExpiry determines where the key has an expiry value

func (ExpiryRecord) TTL

func (r ExpiryRecord) TTL(now time.Time) (time.Duration, error)

TTL uses a specific time.Time ("now") and works out the TTL of the key (always >=1s), or 0 if no expiry An error is returned if the key does not exist in the expiry records (no expiry)

type Options

type Options struct {
	Clock             clock
	CompactorFunc     func()
	CompactorInterval time.Duration
}

Directories

Path Synopsis
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
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
Implement expiry within the the actual value storage The underlying store will need to use this when Inserting/Retrieving
Implement expiry within the the actual value storage The underlying store will need to use this when Inserting/Retrieving

Jump to

Keyboard shortcuts

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