使用空struct{}代替bool节约内存

This commit is contained in:
GoEdgeLab
2021-12-09 12:07:46 +08:00
parent 6be26c0ffb
commit 82709e274c
15 changed files with 126 additions and 63 deletions

View File

@@ -4,6 +4,7 @@ package ttlcache
import (
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"sync"
"time"
)
@@ -14,13 +15,13 @@ type Manager struct {
ticker *time.Ticker
locker sync.Mutex
cacheMap map[*Cache]bool
cacheMap map[*Cache]zero.Zero
}
func NewManager() *Manager {
var manager = &Manager{
ticker: time.NewTicker(3 * time.Second),
cacheMap: map[*Cache]bool{},
cacheMap: map[*Cache]zero.Zero{},
}
goman.New(func() {
@@ -42,7 +43,7 @@ func (this *Manager) init() {
func (this *Manager) Add(cache *Cache) {
this.locker.Lock()
this.cacheMap[cache] = true
this.cacheMap[cache] = zero.New()
this.locker.Unlock()
}