mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-07 10:40:26 +08:00
优化ttlcache
This commit is contained in:
@@ -54,7 +54,7 @@ func NewCache(opt ...OptionInterface) *Cache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := &Cache{
|
var cache = &Cache{
|
||||||
countPieces: uint64(countPieces),
|
countPieces: uint64(countPieces),
|
||||||
maxItems: maxItems,
|
maxItems: maxItems,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,13 @@ func TestCache_GC2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCacheDestroy(t *testing.T) {
|
||||||
|
var cache = NewCache()
|
||||||
|
t.Log("count:", SharedManager.Count())
|
||||||
|
cache.Destroy()
|
||||||
|
t.Log("count:", SharedManager.Count())
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkNewCache(b *testing.B) {
|
func BenchmarkNewCache(b *testing.B) {
|
||||||
runtime.GOMAXPROCS(1)
|
runtime.GOMAXPROCS(1)
|
||||||
|
|
||||||
|
|||||||
@@ -52,3 +52,9 @@ func (this *Manager) Remove(cache *Cache) {
|
|||||||
delete(this.cacheMap, cache)
|
delete(this.cacheMap, cache)
|
||||||
this.locker.Unlock()
|
this.locker.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Manager) Count() int {
|
||||||
|
this.locker.Lock()
|
||||||
|
defer this.locker.Unlock()
|
||||||
|
return len(this.cacheMap)
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ccCache = ttlcache.NewCache(ttlcache.NewPiecesOption(32))
|
var ccCache = ttlcache.NewCache()
|
||||||
|
|
||||||
// CC2Checkpoint 新的CC
|
// CC2Checkpoint 新的CC
|
||||||
type CC2Checkpoint struct {
|
type CC2Checkpoint struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user