This commit is contained in:
GoEdgeLab
2024-07-27 15:42:58 +08:00
parent 7279dc873f
commit d7d0c8fbfe
490 changed files with 2158 additions and 738 deletions

View File

@@ -1,8 +1,9 @@
package ttlcache
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"time"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
)
var DefaultCache = NewCache()

View File

@@ -1,11 +1,12 @@
package ttlcache
import (
"github.com/iwind/TeaGo/rands"
"runtime"
"strconv"
"testing"
"time"
"github.com/iwind/TeaGo/rands"
)
func TestNewCache(t *testing.T) {
@@ -68,7 +69,7 @@ func TestCache_Read(t *testing.T) {
total := 0
for _, piece := range cache.pieces {
//t.Log(len(piece.m), "keys")
// t.Log(len(piece.m), "keys")
total += len(piece.m)
}
t.Log(total, "total keys")

View File

@@ -1,9 +1,10 @@
package ttlcache
import (
"github.com/iwind/TeaGo/types"
"sync"
"time"
"github.com/iwind/TeaGo/types"
)
type Piece struct {
@@ -16,7 +17,7 @@ func NewPiece(maxItems int) *Piece {
return &Piece{m: map[uint64]*Item{}, maxItems: maxItems}
}
func (this *Piece) Add(key uint64, item *Item) () {
func (this *Piece) Add(key uint64, item *Item) {
this.locker.Lock()
if len(this.m) >= this.maxItems {
this.locker.Unlock()

View File

@@ -1,9 +1,10 @@
package ttlcache
import (
"github.com/iwind/TeaGo/rands"
"testing"
"time"
"github.com/iwind/TeaGo/rands"
)
func TestPiece_Add(t *testing.T) {