根据系统内存自动调节ttlcache的最大条目

This commit is contained in:
GoEdgeLab
2021-10-04 09:12:17 +08:00
parent 4d8565d583
commit 19b373c18c
6 changed files with 55 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package ttlcache
import (
"github.com/shirou/gopsutil/mem"
)
var systemTotalMemory = -1
func systemMemoryGB() int {
if systemTotalMemory > 0 {
return systemTotalMemory
}
stat, err := mem.VirtualMemory()
if err != nil {
return 0
}
systemTotalMemory = int(stat.Total / 1024 / 1024 / 1024)
return systemTotalMemory
}