cache

package
v0.2.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package cache provides a factory function to create Cache instances.

Index

Constants

View Source
const (
	DefaultDriver = "memory" // Define a default driver
)
View Source
const Module = "storage.cache"

Variables

View Source
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

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

func Register(name string, factory Factory)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL