timecache

package
v1.1.10-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPeerTimeCache added in v1.0.127

func NewPeerTimeCache(timeCache storage.TimeCacher) (*peerTimeCache, error)

NewPeerTimeCache creates a new peer time cache data structure instance

Types

type TimeCache

type TimeCache struct {
	// contains filtered or unexported fields
}

TimeCache can retain an amount of string keys for a defined period of time sweeping (clean-up) is triggered each time a new item is added or a key is present in the time cache This data structure is concurrent safe.

func NewTimeCache

func NewTimeCache(defaultSpan time.Duration) *TimeCache

NewTimeCache creates a new time cache data structure instance

func (*TimeCache) Add

func (tc *TimeCache) Add(key string) error

Add will store the key in the time cache Double adding the key is not permitted by the time cache. Also, add will trigger sweeping.

func (*TimeCache) AddWithSpan added in v1.0.120

func (tc *TimeCache) AddWithSpan(key string, duration time.Duration) error

AddWithSpan will store the key in the time cache with the provided span duration Double adding the key is not permitted by the time cache. Also, add will trigger sweeping.

func (*TimeCache) Has

func (tc *TimeCache) Has(key string) bool

Has returns if the key is still found in the time cache

func (*TimeCache) IsInterfaceNil

func (tc *TimeCache) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*TimeCache) Len added in v1.1.1

func (tc *TimeCache) Len() int

Len returns the number of elements which are still stored in the time cache

func (*TimeCache) Sweep

func (tc *TimeCache) Sweep()

Sweep starts from the oldest element and will search each element if it is still valid to be kept. Sweep ends when it finds an element that is still valid

func (*TimeCache) Upsert added in v1.0.133

func (tc *TimeCache) Upsert(key string, duration time.Duration) error

Upsert will add the key and provided duration if not exists If the record exists, will update the duration if the provided duration is larger than existing Also, it will reset the contained timestamp to time.Now

Jump to

Keyboard shortcuts

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