ttlstore

package module
v0.0.0-...-73c2cd7 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: MIT Imports: 6 Imported by: 0

README

go-ttlstore

Simple Golang TTL store

It is a sync.Map wrapped with functions cleaning it. It allows to set a Janitor which is notified about changes in store.

Provided Janitor:

  • keeps the number of items under N (keep the most recent ones)
  • deletes old items (maxAge)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteHook

type DeleteHook func(key interface{})

type Deleter

type Deleter struct {
	DeleteFunc DeleteHook
	Interval   time.Duration
	Name       string
	Now        func() time.Time
	// contains filtered or unexported fields
}

Deleter implements a clean up mechanism. Deleter keeps at least `keep` items. The items must be younger then `maxAge`. One should call Set method for keys one wants to keep for a specific time. The deletion process is triggered by a timer set to `Interval` value. It removes items from the oldest to the newest until we have less than `keep` items.

func NewDeleter

func NewDeleter(name string, del DeleteHook, maxAge, runInterval time.Duration,
	bufSize, keep int, logger logrus.FieldLogger) *Deleter

func (*Deleter) Deleting

func (d *Deleter) Deleting()

func (*Deleter) Process

func (d *Deleter) Process()

func (*Deleter) Set

func (d *Deleter) Set(key interface{}, insert time.Time)

func (*Deleter) Start

func (d *Deleter) Start()

func (*Deleter) Stop

func (d *Deleter) Stop()

type DeleterProvider

type DeleterProvider func(name string, hook DeleteHook) *Deleter

func NewDeleterProvider

func NewDeleterProvider(maxAge, interval time.Duration, bufSize, keep int) DeleterProvider

type SetCallback

type SetCallback func(key interface{}, insert time.Time)

type TtlStore

type TtlStore struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

TtlStore is a map store with callback on Set. It wraps around the sync.Map. It adds `Delete` method used by Deleter.

func New

func New(c SetCallback) *TtlStore

func (*TtlStore) Delete

func (t *TtlStore) Delete(key interface{})

func (*TtlStore) Get

func (t *TtlStore) Get(key interface{}) interface{}

func (*TtlStore) GetHas

func (t *TtlStore) GetHas(key interface{}) (interface{}, bool)

func (*TtlStore) Has

func (t *TtlStore) Has(key interface{}) bool

func (*TtlStore) Set

func (t *TtlStore) Set(key, value interface{})

Jump to

Keyboard shortcuts

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