timecache

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FirstSeenCache

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

FirstSeenCache is a time cache that only marks the expiry of a message when first added.

func (*FirstSeenCache) Add

func (tc *FirstSeenCache) Add(s string) bool

func (*FirstSeenCache) Done

func (tc *FirstSeenCache) Done()

func (*FirstSeenCache) Has

func (tc *FirstSeenCache) Has(s string) bool

type LastSeenCache

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

LastSeenCache is a time cache that extends the expiry of a seen message when added or checked for presence with Has..

func (*LastSeenCache) Add

func (tc *LastSeenCache) Add(s string) bool

func (*LastSeenCache) Done

func (tc *LastSeenCache) Done()

func (*LastSeenCache) Has

func (tc *LastSeenCache) Has(s string) bool

type Strategy

type Strategy uint8

Stategy is the TimeCache expiration strategy to use.

const (
	// Strategy_FirstSeen expires an entry from the time it was added.
	Strategy_FirstSeen Strategy = iota
	// Stategy_LastSeen expires an entry from the last time it was touched by an Add or Has.
	Strategy_LastSeen
)

type TimeCache

type TimeCache interface {
	// Add adds an id into the cache, if it is not already there.
	// Returns true if the id was newly added to the cache.
	// Depending on the implementation strategy, it may or may not update the expiry of
	// an existing entry.
	Add(string) bool
	// Has checks the cache for the presence of an id.
	// Depending on the implementation strategy, it may or may not update the expiry of
	// an existing entry.
	Has(string) bool
	// Done signals that the user is done with this cache, which it may stop background threads
	// and relinquish resources.
	Done()
}

TimeCache is a cahe of recently seen messages (by id).

func NewTimeCache

func NewTimeCache(ttl time.Duration) TimeCache

NewTimeCache defaults to the original ("first seen") cache implementation

func NewTimeCacheWithStrategy

func NewTimeCacheWithStrategy(strategy Strategy, ttl time.Duration) TimeCache

Jump to

Keyboard shortcuts

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