mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 06:40:25 +08:00
将获取系统内存函数放入到utils中
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ttlcache
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -24,7 +25,7 @@ func NewCache(opt ...OptionInterface) *Cache {
|
||||
var countPieces = 128
|
||||
var maxItems = 2_000_000
|
||||
|
||||
var totalMemory = systemMemoryGB()
|
||||
var totalMemory = utils.SystemMemoryGB()
|
||||
if totalMemory < 2 {
|
||||
// 我们限制内存过小的服务能够使用的数量
|
||||
maxItems = 1_000_000
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ttlcache
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
@@ -8,7 +8,11 @@ import (
|
||||
|
||||
var systemTotalMemory = -1
|
||||
|
||||
func systemMemoryGB() int {
|
||||
func init() {
|
||||
_ = SystemMemoryGB()
|
||||
}
|
||||
|
||||
func SystemMemoryGB() int {
|
||||
if systemTotalMemory > 0 {
|
||||
return systemTotalMemory
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ttlcache
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSystemMemoryGB(t *testing.T) {
|
||||
t.Log(systemMemoryGB())
|
||||
t.Log(systemMemoryGB())
|
||||
t.Log(systemMemoryGB())
|
||||
t.Log(SystemMemoryGB())
|
||||
t.Log(SystemMemoryGB())
|
||||
t.Log(SystemMemoryGB())
|
||||
}
|
||||
Reference in New Issue
Block a user