prefetching

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 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 OnEntryReloadedCallback

type OnEntryReloadedCallback func(key string)

OnEntryReloadedCallback will be called if a prefetched entry is reloaded

type PrefetchingCacheOption

type PrefetchingCacheOption[T any] func(c *PrefetchingExpiringLRUCache[cacheValue[T]])

type PrefetchingExpiringLRUCache

type PrefetchingExpiringLRUCache[T any] struct {
	// contains filtered or unexported fields
}

func NewPrefetchingCache

func NewPrefetchingCache[T any](ctx context.Context, options PrefetchingOptions[T]) *PrefetchingExpiringLRUCache[T]

func (*PrefetchingExpiringLRUCache[T]) Clear

func (e *PrefetchingExpiringLRUCache[T]) Clear()

Clear removes all cache entries

func (*PrefetchingExpiringLRUCache[T]) Get

func (e *PrefetchingExpiringLRUCache[T]) Get(key string) (val *T, expiration time.Duration)

Get returns the value of cached entry with remained TTL. If entry is not cached, returns nil

func (*PrefetchingExpiringLRUCache[T]) Put

func (e *PrefetchingExpiringLRUCache[T]) Put(key string, val *T, expiration time.Duration)

func (*PrefetchingExpiringLRUCache[T]) SetReloadPublisher added in v0.31.0

func (e *PrefetchingExpiringLRUCache[T]) SetReloadPublisher(fn func(key string, val *T, ttl time.Duration))

SetReloadPublisher registers a function invoked with each entry reloaded by prefetching. A cache decorator uses it to propagate reloaded entries (which are stored directly by the inner expiration cache and so bypass the decorator).

func (*PrefetchingExpiringLRUCache[T]) TotalCount

func (e *PrefetchingExpiringLRUCache[T]) TotalCount() int

TotalCount returns the total count of valid (not expired) elements

type PrefetchingOptions

type PrefetchingOptions[T any] struct {
	expirationcache.Options

	ReloadFn                ReloadEntryFn[T]
	PrefetchThreshold       int
	PrefetchExpires         time.Duration
	PrefetchMaxItemsCount   int
	OnPrefetchAfterPut      expirationcache.OnAfterPutCallback
	OnPrefetchEntryReloaded OnEntryReloadedCallback
	OnPrefetchCacheHit      expirationcache.OnCacheHitCallback
}

type ReloadEntryFn

type ReloadEntryFn[T any] func(ctx context.Context, key string) (*T, time.Duration)

ReloadEntryFn reloads a prefetched entry by key

Jump to

Keyboard shortcuts

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