prefetching

package
v0.28.2 Latest Latest
Warning

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

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

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]) 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