优化代码

This commit is contained in:
GoEdgeLab
2021-12-22 16:43:16 +08:00
parent fb06b22d60
commit e84ca26aa6
6 changed files with 45 additions and 20 deletions

View File

@@ -21,12 +21,18 @@ type Cache struct {
}
func NewCache(opt ...OptionInterface) *Cache {
countPieces := 128
maxItems := 2_000_000
var countPieces = 128
var maxItems = 2_000_000
var delta = systemMemoryGB() / 8
if delta > 0 {
maxItems *= delta
var totalMemory = systemMemoryGB()
if totalMemory < 2 {
// 我们限制内存过小的服务能够使用的数量
maxItems = 1_000_000
} else {
var delta = totalMemory / 8
if delta > 0 {
maxItems *= delta
}
}
for _, option := range opt {