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 wrapping them with metric collection and marshaling capabilities (ProtoBuf or MsgPack) before returning a loadable or namespaced cache.
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
| Name | Type | Description |
|---|---|---|
| name | string | The name of the cache, used for scoping Prometheus metrics and for namespacing the cache. |
| cacheType | Type | The type of cache to create, determining the underlying storage mechanism (e.g., in-memory fixed size or Redis). |
| f | Factory | A factory object providing the necessary components for creating cache stores, such as in-memory and Redis cache implementations. |
| loadFunc | cache.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. |
| scope | promutils.Scope | The Prometheus scope to use for registering metrics related to the cache's performance and usage. |
Returns
| Type | Description |
|---|---|
cache.CacheInterface[T], error | A new cache instance configured with the specified type, marshaler, and an optional load function, or an error if the cache cannot be created. |