Skip to main content

NewInMemoryAutoRefresh

Creates a new InMemoryAutoRefresh.

def NewInMemoryAutoRefresh(
name: string,
syncCb: SyncFunc,
syncRateLimiter: workqueue.TypedRateLimiter[*Batch],
resyncPeriod: time.Duration,
parallelizm: uint,
size: uint,
scope: promutils.Scope,
options: ...Option
) - > (*InMemoryAutoRefresh, error)

Creates a new InMemoryAutoRefresh instance. This function initializes an auto-refresh mechanism that periodically synchronizes data using a provided callback function and manages a cache of items.

Parameters

NameTypeDescription
namestringA descriptive name for this InMemoryAutoRefresh instance, used for logging and metrics.
syncCbSyncFuncThe callback function responsible for synchronizing data. This function will be invoked periodically to refresh the cached items.
syncRateLimiterworkqueue.TypedRateLimiter[*Batch]A rate limiter to control the frequency of synchronization operations, preventing excessive calls to the sync callback.
resyncPeriodtime.DurationThe duration after which a full resynchronization of all items should occur, ensuring data freshness.
parallelizmuintThe number of concurrent workers that can process synchronization batches, controlling the parallelism of the refresh process.
sizeuintThe maximum number of items the underlying LRU cache can hold. When this limit is reached, the least recently used items will be evicted.
scopepromutils.ScopeThe Prometheus metrics scope to which metrics related to this auto-refresh instance will be reported.
options...OptionOptional configuration parameters to customize the behavior of the InMemoryAutoRefresh instance, such as clock implementation or batch creation callback.

Returns

TypeDescription
(*InMemoryAutoRefresh, error)A pointer to the newly created InMemoryAutoRefresh instance and an error if the LRU cache creation fails.