cachefx

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFactoryConfig = errors.New("invalid config")
)

Functions

func Module

func Module(opts ...Option) fx.Option

Module provides the cache Factory and, with WithSweeper, registers the Sweeper to periodically evict expired entries from every cache the factory hands out.

Types

type Config

type Config struct {
	URL string

	// SweepInterval is how often the Sweeper evicts expired entries from every
	// cache created by the Factory. A non-positive value disables sweeping:
	// NewSweeper rejects it, so a module wired with withRun=true fails at
	// startup instead of silently never sweeping.
	SweepInterval time.Duration
}

Config controls the cache backend via a URL (e.g., "memory://", "redis://...") and the sweeper.

type Factory

type Factory interface {
	New(name string) (cache.Cache, error)
	WithName(name string) Factory

	// CleanupAll evicts expired entries from every cache handed out by this
	// factory, including the ones created by factories derived from it through
	// WithName.
	CleanupAll(ctx context.Context) error
}

func NewFactory

func NewFactory(config Config) (Factory, error)

type Option added in v0.2.0

type Option func(*moduleConfig)

Option configures Module.

func WithSweeper added in v0.2.0

func WithSweeper() Option

WithSweeper registers the Sweeper as a runnable, so Config.SweepInterval must be positive or the app fails at startup.

type Sweeper added in v0.2.0

type Sweeper struct {
	// contains filtered or unexported fields
}

Sweeper periodically evicts expired entries from every cache created by the Factory.

Eviction of expired entries is not guaranteed by every backend: the in-memory backend keeps expired items until an explicit Cleanup, and each New call returns a distinct instance, so the sweeper walks every cache the factory has handed out.

func NewSweeper added in v0.2.0

func NewSweeper(config Config, factory Factory, logger *zap.Logger) (*Sweeper, error)

NewSweeper creates a Sweeper running every config.SweepInterval.

It fails when the interval is not positive, so a module wired to run the sweeper fails at startup instead of silently never sweeping.

func (*Sweeper) Run added in v0.2.0

func (s *Sweeper) Run(ctx context.Context) error

Run evicts expired entries until ctx is canceled.

Directories

Path Synopsis
Package cache provides a flexible caching abstraction with multiple backend implementations.
Package cache provides a flexible caching abstraction with multiple backend implementations.

Jump to

Keyboard shortcuts

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