Skip to main content

New

Creates a new cache with the specified name, type, factory, load function, and Prometheus scope. It supports in-memory fixed-size caches or Redis-backed caches, optionally wrapped with Prometheus metrics and a marshaler for data serialization.

def New(
name: string,
cacheType: Type,
f: Factory,
loadFunc: cache.LoadFunction[T],
scope: promutils.Scope
) - > cache.CacheInterface[T], error

Creates a new cache with the given name and load function.

Parameters

NameTypeDescription
namestringThe name of the cache, used for scoping Prometheus metrics and for namespacing the cache.
cacheTypeTypeThe type of cache to create, determining the underlying storage mechanism (e.g., in-memory fixed size or Redis).
fFactoryA factory object providing the necessary components for creating cache stores, such as in-memory and Redis cache implementations.
loadFunccache.LoadFunction[T]An optional function that will be called to load data into the cache if a requested key is not found. If nil, the cache will not be loadable.
scopepromutils.ScopeThe Prometheus scope to use for metrics, allowing for hierarchical metric naming.

Returns

TypeDescription
cache.CacheInterface[T], errorA new cache instance configured with the specified type, marshaler, and an optional load function, or an error if the cache cannot be created.