Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpiringCache ¶
type ExpiringCache[T any] interface { // Put adds the value to the cache unter the passed key with expiration. If expiration <=0, entry will NOT be cached Put(key string, val *T, expiration time.Duration) // Get returns the value of cached entry with remained TTL. If entry is not cached, returns nil Get(key string) (val *T, expiration time.Duration) // TotalCount returns the total count of valid (not expired) elements TotalCount() int // Clear removes all cache entries Clear() }
type ExpiringLRUCache ¶
type ExpiringLRUCache[T any] struct { // contains filtered or unexported fields }
func NewCacheWithOnExpired ¶
func NewCacheWithOnExpired[T any](ctx context.Context, options Options, onExpirationFn OnExpirationCallback[T], ) *ExpiringLRUCache[T]
func (*ExpiringLRUCache[T]) Clear ¶
func (e *ExpiringLRUCache[T]) Clear()
func (*ExpiringLRUCache[T]) Get ¶
func (e *ExpiringLRUCache[T]) Get(key string) (val *T, ttl time.Duration)
func (*ExpiringLRUCache[T]) Put ¶
func (e *ExpiringLRUCache[T]) Put(key string, val *T, ttl time.Duration)
func (*ExpiringLRUCache[T]) TotalCount ¶
func (e *ExpiringLRUCache[T]) TotalCount() (count int)
type OnAfterPutCallback ¶
type OnAfterPutCallback func(newSize int)
OnAfterPutCallback will be called after put, receives new element count as parameter
type OnCacheHitCallback ¶
type OnCacheHitCallback func(key string)
OnCacheHitCallback will be called on cache get if entry was found
type OnCacheMissCallback ¶
type OnCacheMissCallback func(key string)
OnCacheMissCallback will be called on cache get and entry was not found
type OnEntryReloadedCallback ¶
type OnEntryReloadedCallback func(key string)
OnEntryReloadedCallback will be called if a prefetched entry is reloaded
type OnExpirationCallback ¶
OnExpirationCallback will be called just before an element gets expired and will be removed from cache. This function can return new value and TTL to leave the element in the cache or nil to remove it
type Options ¶
type Options struct {
OnCacheHitFn OnCacheHitCallback
OnCacheMissFn OnCacheMissCallback
OnAfterPutFn OnAfterPutCallback
CleanupInterval time.Duration
MaxSize uint
}
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 { Options ReloadFn ReloadEntryFn[T] PrefetchThreshold int PrefetchExpires time.Duration PrefetchMaxItemsCount int OnPrefetchAfterPut OnAfterPutCallback OnPrefetchEntryReloaded OnEntryReloadedCallback OnPrefetchCacheHit OnCacheHitCallback }