Documentation
¶
Overview ¶
Package cache provides a factory function to create Cache instances.
Index ¶
Constants ¶
const (
DefaultDriver = "memory" // Define a default driver
)
const Module = "storage.cache"
Variables ¶
var DefaultProvider component.Provider = func(ctx context.Context, h component.Handle) (any, error) { cfg, err := comp.AsConfig[cachev1.CacheConfig](h) if err != nil { return nil, err } return New(cfg) }
DefaultProvider is the default provider for cache components.
Functions ¶
func New ¶
func New(cfg *cachev1.CacheConfig, opts ...options.Option) (storageiface.Cache, error)
New creates a new Cache instance based on the provided configuration. It uses the internal factory registry to find the appropriate provider. To use a specific provider (e.g., "redis"), ensure its package is imported for its side effects (e.g., `import _ "path/to/redis/provider"`), which will register the provider's factory.
func Register ¶ added in v0.2.13
Register registers a new cache factory with the default factory registry.
func Resolve ¶ added in v0.2.19
func Resolve(ctx context.Context, source any, opts *component.LoadOptions) (*component.ModuleConfig, error)
Resolve resolves the cache configuration.
Types ¶
type Factory ¶ added in v0.2.13
type Factory interface {
NewCache(cfg *cachev1.CacheConfig, opts ...options.Option) (storageiface.Cache, error)
}
Factory is the interface for creating new Cache components.
type FactoryFunc ¶ added in v0.2.13
type FactoryFunc func(cfg *cachev1.CacheConfig, opts ...options.Option) (storageiface.Cache, error)
FactoryFunc is a function type that implements the Factory interface.
func (FactoryFunc) NewCache ¶ added in v0.2.13
func (f FactoryFunc) NewCache(cfg *cachev1.CacheConfig, opts ...options.Option) (storageiface.Cache, error)
NewCache creates a new Cache component based on the provided configuration.