Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 包含缓存系统的配置选项
type Option ¶
Option is a function type that takes a pointer to Config and returns an error. It is used for configuring instances.
func WithLogger ¶
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 ¶
WithMaxLocalSize sets the maximum size for the local cache, dynamically calculates shard count, and returns an Option.
func WithPrefetchInterval ¶ added in v0.0.2
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 ¶
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.