cache

package
v3.5.6 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 3 Imported by: 3 modules, 8 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

func DefaultOnExpire

func DefaultOnExpire[D any](D)

Types

type Cache

type Cache[K comparable, D any] struct {
	*sync.Map[K, *Element[D]]
}

func NewCache

func NewCache[K comparable, D any]() *Cache[K, D]

func (*Cache[K, D]) CheckExpirations

func (c *Cache[K, D]) CheckExpirations(now time.Time)

func (*Cache[K, D]) Load

func (c *Cache[K, D]) Load(key K) (actual *Element[D])

func (*Cache[K, D]) LoadOrStore

func (c *Cache[K, D]) LoadOrStore(key K, e *Element[D]) (actual *Element[D], loaded bool)

type Element

type Element[D any] struct {
	ValidUntil atomic.Time
	// contains filtered or unexported fields
}

func NewElement

func NewElement[D any](data D, validUntil time.Time, onExpire func(d D)) *Element[D]

func (*Element[D]) Data

func (e *Element[D]) Data() D

func (*Element[D]) IsExpired

func (e *Element[D]) IsExpired(now time.Time) bool

Jump to

Keyboard shortcuts

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