From 1101a54fe80dac89c16f6fc1c9907f213835c456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=B5=B7=E8=88=AA?= <1932859223@qq.com> Date: Thu, 31 Oct 2024 03:23:52 +0800 Subject: [PATCH] validate NumCounters, MaxCost, BufferItems in NewCache (#410) Co-authored-by: zhaohaihang <1932859223@com> --- cache.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cache.go b/cache.go index d29c93d0..4e8e0dac 100644 --- a/cache.go +++ b/cache.go @@ -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 }