Skip to content

Commit

Permalink
Perform validation to ensure that the three parameters, NumCounters, …
Browse files Browse the repository at this point in the history
…MaxCost, and BufferItems, are all greater than 0.(hypermodeinc#378)
  • Loading branch information
zhaohaihang committed Oct 29, 2024
1 parent f4f0d7e commit d3fa633
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 d3fa633

Please sign in to comment.