timecache

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 4 Imported by: 14

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 thread-safe copy of https://github.com/whyrusleeping/timecache.

func (FirstSeenCache) Add

func (tc FirstSeenCache) Add(s string)

func (FirstSeenCache) Has

func (tc FirstSeenCache) Has(s string) bool

type LastSeenCache

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

LastSeenCache is a LRU cache that keeps entries for up to a specified time duration. After this duration has elapsed, "old" entries will be purged from the cache.

It's also a "sliding window" cache. Every time an unexpired entry is seen again, its timestamp slides forward. This keeps frequently occurring entries cached and prevents them from being propagated, especially because of network issues that might increase the number of duplicate messages in the network.

Garbage collection of expired entries is event-driven, i.e. it only happens when there is a new entry added to the cache. This should be ok - if existing entries are being looked up then the cache is not growing, and when a new one appears that would grow the cache, garbage collection will attempt to reduce the pressure on the cache.

This implementation is heavily inspired by https://github.com/whyrusleeping/timecache.

func (*LastSeenCache) Add

func (tc *LastSeenCache) Add(s string)

func (*LastSeenCache) Has

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

type Strategy

type Strategy uint8
const (
	Strategy_FirstSeen Strategy = iota
	Strategy_LastSeen
)

type TimeCache

type TimeCache interface {
	Add(string)
	Has(string) bool
}

func NewTimeCache

func NewTimeCache(span time.Duration) TimeCache

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

func NewTimeCacheWithStrategy

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

Jump to

Keyboard shortcuts

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