优化代码

This commit is contained in:
刘祥超
2024-03-28 17:17:34 +08:00
parent f119690ab7
commit f1d0984031
27 changed files with 52 additions and 63 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
package ttlcache
import (
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"runtime"
)
@@ -25,7 +25,7 @@ type Cache[T any] struct {
}
func NewBigCache[T any]() *Cache[T] {
var delta = utils.SystemMemoryGB() / 2
var delta = memutils.SystemMemoryGB() / 2
if delta <= 0 {
delta = 1
}
@@ -36,7 +36,7 @@ func NewCache[T any](opt ...OptionInterface) *Cache[T] {
var countPieces = 256
var maxItems = 1_000_000
var totalMemory = utils.SystemMemoryGB()
var totalMemory = memutils.SystemMemoryGB()
if totalMemory < 2 {
// 我们限制内存过小的服务能够使用的数量
maxItems = 500_000
+2 -2
View File
@@ -1,8 +1,8 @@
package ttlcache
import (
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/rands"
@@ -60,7 +60,7 @@ func TestCache_Memory(t *testing.T) {
})
var count = 1_000_000
if utils.SystemMemoryGB() > 4 {
if memutils.SystemMemoryGB() > 4 {
count = 20_000_000
}
for i := 0; i < count; i++ {