Skip to main content

NewAutoRefreshCache

No overview available.

def NewAutoRefreshCache(
syncCb: CacheSyncItem,
syncRateLimiter: RateLimiter,
resyncPeriod: time.Duration,
size: int,
scope: promutils.Scope
) - > AutoRefreshCache, error

Deprecated: This utility is deprecated, it has been refactored and moved into cache package. Creates a new AutoRefreshCache instance, which is a cache that automatically refreshes its items based on a provided synchronization callback and resynchronization period. This function is used to initialize a cache that can manage and refresh data with rate limiting and optional Prometheus metrics for evictions.

Parameters

NameTypeDescription
syncCbCacheSyncItemThe callback function used to synchronize items within the cache. This function defines how individual cache items are refreshed.
syncRateLimiterRateLimiterThe rate limiter to control the frequency of synchronization operations, preventing excessive calls to the sync callback.
resyncPeriodtime.DurationThe duration after which the cache should attempt to resynchronize its items, ensuring data freshness.
sizeintThe maximum number of items the cache can hold. When this limit is exceeded, the least recently used items will be evicted.
scopepromutils.ScopeAn optional Prometheus scope for metrics. If provided, a counter for LRU evictions will be created and incremented when items are removed from the cache.

Returns

TypeDescription
AutoRefreshCache, errorA new AutoRefreshCache instance if successful, otherwise an error.