Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidFactoryConfig = errors.New("invalid config")
)
Functions ¶
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 ¶
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
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.