通过内存缓存提升文件缓存效率大约20%

This commit is contained in:
GoEdgeLab
2021-08-21 21:06:48 +08:00
parent 53f3a56972
commit 7a452c5a6f
6 changed files with 56 additions and 8 deletions

View File

@@ -17,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()
@@ -82,6 +82,12 @@ func (this *Piece) GC() {
this.locker.Unlock()
}
func (this *Piece) Clean() {
this.locker.Lock()
this.m = map[uint64]*Item{}
this.locker.Unlock()
}
func (this *Piece) Destroy() {
this.locker.Lock()
this.m = nil