cache

package
v17.0.1-rc42 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 6 Imported by: 0

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