Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DefaultMaxStatsSize defines the default maximum size of statistics. DefaultMaxStatsSize = 100000 // DefaultBatchSize defines the default size of the key batch for warming. DefaultBatchSize = DefaultMaxStatsSize / defaultBatchToMaxMultiplier // DefaultRateInterval defines the default update rate interval. DefaultRateInterval = RateInterval15 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config[K comparable] struct { // Interval between warming cycles. Interval time.Duration // Number of keys to warm up in one cycle. // If 0, the default value is used (MaxStatsSize/10). BatchSize int // MaxStatsSize defines the maximum number of records in statistics. // When this value is exceeded, old records will be removed. // If 0, the default value is used (100000). MaxStatsSize int // RateInterval defines the update rate interval. // If 0, the default value is used (15 minutes). RateInterval RateIntervalType // Callback for collecting key statistics. // Called on each key track. OnKeyTrack OnKeyTrackFunc[K] // Callback for collecting database read error statistics. // Called on each read error. OnDBError OnErrorFunc[K] // Callback for collecting cache write error statistics. // Called on each write error. OnCacheError OnErrorFunc[K] // OnWarmTrack is called when a key is warmed up. OnWarmTrack OnKeyWarmFunc[K] }
Config contains Warmer settings.
func DefaultConfig ¶
func DefaultConfig[K comparable]() Config[K]
DefaultConfig returns the default configuration.
type GetFromDBFunc ¶
type GetFromDBFunc[K comparable, V any] func(ctx context.Context, key K) (V, error)
GetFromDBFunc defines a function for retrieving an object from the database.
type OnErrorFunc ¶
type OnErrorFunc[K comparable] func(ctx context.Context, key K, err error)
OnErrorFunc defines a function for handling errors.
type OnKeyTrackFunc ¶
type OnKeyTrackFunc[K comparable] func(ctx context.Context, key K, rate float64)
OnKeyTrackFunc defines a function for handling key tracking.
type OnKeyWarmFunc ¶
type OnKeyWarmFunc[K comparable] func(ctx context.Context, key K, rate float64)
OnKeyWarmFunc defines a function for handling key tracking.
type RateIntervalType ¶
type RateIntervalType int
RateIntervalType defines the update rate interval.
const ( RateInterval1 RateIntervalType = iota // RateInterval1 1 minute RateInterval5 // RateInterval5 5 minutes RateInterval15 // RateInterval15 15 minutes )
type SetToCacheFunc ¶
type SetToCacheFunc[K comparable, V any] func(ctx context.Context, key K, value V) error
SetToCacheFunc defines a function for saving an object to the cache.
type Warmer ¶
type Warmer[K comparable, V any] struct { // contains filtered or unexported fields }
Warmer provides cache warming functionality.
func New ¶
func New[K comparable, V any]( getFromDB GetFromDBFunc[K, V], setToCache SetToCacheFunc[K, V], config Config[K], ) *Warmer[K, V]
New creates a new warmer instance with specified database and cache access functions.
Click to show internal directories.
Click to hide internal directories.