config

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShardCountZero = errors.New("shard count must be at least 1")
)

ErrShardCountZero indicates an error condition where the shard count is zero, which is not allowed.

Functions

func CalculateDynamicShardCount

func CalculateDynamicShardCount(maxSize, avgItemSize uint64) uint64

CalculateDynamicShardCount dynamically calculates the number of shards needed based on maxSize and avgItemSize.

Types

type AdaptiveTTLConfig

type AdaptiveTTLConfig struct {
	MinTTL            time.Duration
	MaxTTL            time.Duration
	TTLAdjustInterval time.Duration
}

AdaptiveTTLConfig defines a configuration for adaptive TTL (Time-To-Live) adjustments for cached items. It includes parameters for minimum and maximum TTL durations and the interval at which the TTL is adjusted.

type BloomFilterConfig

type BloomFilterConfig struct {
	ExpectedItems       uint
	FalsePositiveRate   float64
	RebuildInterval     time.Duration
	BloomFilterRedisKey string
}

BloomFilterConfig represents the configuration for a bloom filter.

type CacheBehaviorConfig

type CacheBehaviorConfig struct {
	EnablePrefetch      bool
	PrefetchThreshold   uint64
	PrefetchCount       uint64
	PrefetchInterval    time.Duration
	WarmupKeys          []string
	EnableAdaptiveTTL   bool
	AdaptiveTTLSettings AdaptiveTTLConfig
	BloomFilterSettings BloomFilterConfig
}

CacheBehaviorConfig encapsulates configuration settings specific to cache behavior, including prefetching and TTL management.

type Config

type Config struct {
	EnableLocalCache  bool
	MaxLocalSize      uint64
	ShardCount        uint64
	DefaultExpiration time.Duration
	CleanupInterval   time.Duration

	CacheBehaviorConfig CacheBehaviorConfig
	ResilienceConfig    ResilienceConfig
	Serialization       SerializationConfig
	RedisOptions        *redis.Options
	Logger              *zap.Logger
}

Config 包含缓存系统的配置选项

func NewConfig

func NewConfig(options ...Option) (*Config, error)

NewConfig initializes a new Config object with default values and applies optional configuration options.

type Option

type Option func(*Config) error

Option is a function type that takes a pointer to Config and returns an error. It is used for configuring instances.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger sets the logger instance for the configuration. If the provided logger is non-nil, it assigns it to the Logger field in the Config structure.

func WithMaxLocalSize

func WithMaxLocalSize(size uint64) Option

WithMaxLocalSize sets the maximum size for the local cache, dynamically calculates shard count, and returns an Option.

func WithPrefetchInterval added in v0.0.2

func WithPrefetchInterval(interval time.Duration) Option

WithPrefetchInterval sets the prefetch interval for the cache, controlling how often prefetching should occur.

func WithResilienceConfig added in v0.0.2

func WithResilienceConfig(rc ResilienceConfig) Option

WithResilienceConfig sets the ResilienceConfig in the Config struct and returns an Option.

func WithShardCount

func WithShardCount(count uint64) Option

WithShardCount sets the number of shards for the cache and returns an Option. It requires a count greater than 0.

type ResilienceConfig

type ResilienceConfig struct {
	GlobalCircuitBreaker gobreaker.Settings
	KeyCircuitBreaker    gobreaker.Settings
	RetrierBackoff       []time.Duration
	MaxRetries           int
	InitialInterval      time.Duration
	MaxInterval          time.Duration
	Multiplier           float64
	RandomizationFactor  float64
}

ResilienceConfig configures resilience mechanisms like circuit breakers and retry backoff.

type SerializationConfig

type SerializationConfig struct {
	Type    string
	Encoder func(io.Writer) serialization.Encoder
	Decoder func(io.Reader) serialization.Decoder
}

SerializationConfig holds the configuration for serialization, including the type, encoder function, and decoder function.

Jump to

Keyboard shortcuts

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