cache

package
v3.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: Apache-2.0 Imports: 3 Imported by: 7

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