package cache

import "github.com/plgd-dev/go-coap/v3/pkg/cache"

Index

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

Source Files

cache.go

Version
v3.3.6 (latest)
Published
Sep 18, 2024
Platform
linux/amd64
Imports
3 packages
Last checked
1 week ago

Tools for package owners.