Skip to main content

NewFactory

Initializes a new cache factory that should be used whenever typed caches are created.

def NewFactory(
ctx: context.Context,
c: *Config,
secretManager: SecretManager,
scope: promutils.Scope
) - > Factory, error

Initializes a new cache factory that should be used whenever typed caches are created. This function sets up either an in-memory fixed-size cache or a Redis-backed cache based on the provided configuration.

Parameters​

NameTypeDescription
ctxcontext.ContextThe context for the operation, used for managing cancellation and deadlines, particularly for Redis client creation.
c*ConfigThe configuration object specifying the cache type (in-memory or Redis) and its settings, including size, expiration, and Redis options.
secretManagerSecretManagerThe secret manager used to retrieve sensitive information, such as Redis credentials, if a Redis cache is configured.
scopepromutils.ScopeThe Prometheus metrics scope used for reporting metrics related to the cache operations, particularly for Redis.

Returns​

TypeDescription
Factory, errorA new Factory instance configured with the specified cache type, or an error if Redis client creation fails.