Skip to content

Commit

Permalink
validate NumCounters, MaxCost, BufferItems in NewCache (#410)
Browse files Browse the repository at this point in the history
Co-authored-by: zhaohaihang <1932859223@com>
  • Loading branch information
zhaohaihang and zhaohaihang authored Oct 30, 2024
1 parent c75fa17 commit 1101a54
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,16 @@ func NewCache[K Key, V any](config *Config[K, V]) (*Cache[K, V], error) {
switch {
case config.NumCounters == 0:
return nil, errors.New("NumCounters can't be zero")
case config.NumCounters < 0:
return nil, errors.New("NumCounters can't be negative number")
case config.MaxCost == 0:
return nil, errors.New("MaxCost can't be zero")
case config.MaxCost < 0:
return nil, errors.New("MaxCost can't be be negative number")
case config.BufferItems == 0:
return nil, errors.New("BufferItems can't be zero")
case config.BufferItems < 0:
return nil, errors.New("BufferItems can't be be negative number")
case config.TtlTickerDurationInSec == 0:
config.TtlTickerDurationInSec = bucketDurationSecs
}
Expand Down

0 comments on commit 1101a54

Please sign in to comment.