timecache

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeCache

type TimeCache[K comparable] struct {
	// contains filtered or unexported fields
}

func New

func New[K comparable](size int, expiry time.Duration) *TimeCache[K]

New allocates a new Timecache with initial allocation size and expiry time. If `size` gets filled the timecache will allocate more memory to fit more elements into it. The cache will not shrink after regrowing. It is safe for concurrent use.

func (*TimeCache[K]) Add

func (tc *TimeCache[K]) Add(value *K)

Add adds a new key into the timecache, it doesn't guard against duplicated entries. Adding the same entry twice will result in undefined behaviour.

func (*TimeCache[K]) Get

func (tc *TimeCache[K]) Get(value *K) bool

Get returns true if the entry exists and it hasn't expired, false otherwise

Jump to

Keyboard shortcuts

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