lrux

package
v1.0.0-beta.217 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTTL

func WithTTL(ttl time.Duration) cacheOptionsFunc

Types

type CacheItemWithTTL

type CacheItemWithTTL[V any] struct {
	Value     V
	ExpiresAt time.Time
}

type CacheWithItemTTL

type CacheWithItemTTL[K comparable, V any] struct {
	*lru.Cache[K, CacheItemWithTTL[V]]
	// contains filtered or unexported fields
}

CacheWithItemTTL is a cache that fetches items with an optional TTL if the TTL has been reached the item is fetched again, otherwise the item is returned from the cache

func NewCacheWithItemTTL

func NewCacheWithItemTTL[K comparable, V any](size int, fetcher Fetcher[K, V], opts ...cacheOptionsFunc) (*CacheWithItemTTL[K, V], error)

func (*CacheWithItemTTL[K, V]) Get

func (c *CacheWithItemTTL[K, V]) Get(ctx context.Context, key K) (V, error)

Get fetches the item from the cache if it exists and is not expired, otherwise it fetches the item from the fetcher

func (*CacheWithItemTTL[K, V]) Refresh

func (c *CacheWithItemTTL[K, V]) Refresh(ctx context.Context, key K) (V, error)

Refresh fetches the item from the fetcher and updates the cache

type Fetcher

type Fetcher[K comparable, V any] func(context.Context, K) (V, error)

Jump to

Keyboard shortcuts

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