cache

package
v16.11.10 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 6 Imported by: 0 modules, 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 Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func New

func New[K comparable, V any](expirationCheckPeriod time.Duration) *Cache[K, V]

func (*Cache[K, V]) EvictEntry

func (c *Cache[K, V]) EvictEntry(key K, entry *Entry[V])

func (*Cache[K, V]) EvictExpiredEntries

func (c *Cache[K, V]) EvictExpiredEntries()

func (*Cache[K, V]) GetOrCreateCacheEntry

func (c *Cache[K, V]) GetOrCreateCacheEntry(key K) *Entry[V]

type CacheWithErr

type CacheWithErr[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewWithError

func NewWithError[K comparable, V any](ttl, errTTL time.Duration, errCacher ErrCacher[K], tracer trace.Tracer,
	isCacheableFunc func(error) bool) *CacheWithErr[K, V]

func (*CacheWithErr[K, V]) GetItem

func (c *CacheWithErr[K, V]) GetItem(ctx context.Context, key K, f GetItemDirectly[V]) (V, error)

type Entry

type Entry[V any] struct {
	// protects state in this object.
	syncz.Mutex
	// Expires holds the time when this entry should be removed from the cache.
	Expires time.Time
	// Item is the cached item.
	Item    V
	HasItem bool
}

func (*Entry[V]) IsExpiredLocked

func (e *Entry[V]) IsExpiredLocked(t time.Time) bool

func (*Entry[V]) IsNeedRefreshLocked

func (e *Entry[V]) IsNeedRefreshLocked() bool

type ErrCacher

type ErrCacher[K any] interface {
	// GetError retrieves a cached error.
	// Returns nil if no cached error found or if there was a problem accessing the cache.
	GetError(ctx context.Context, key K) error
	// CacheError puts error into the cache.
	CacheError(ctx context.Context, key K, err error, errTTL time.Duration)
}

type GetItemDirectly

type GetItemDirectly[V any] func() (V, error)

Jump to

Keyboard shortcuts

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