mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	通过内存缓存提升文件缓存效率大约20%
This commit is contained in:
		@@ -5,7 +5,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// TTL缓存
 | 
			
		||||
// Cache TTL缓存
 | 
			
		||||
// 最大的缓存时间为30 * 86400
 | 
			
		||||
// Piece数据结构:
 | 
			
		||||
//      Piece1          |  Piece2 | Piece3 | ...
 | 
			
		||||
@@ -136,6 +136,12 @@ func (this *Cache) GC() {
 | 
			
		||||
	this.gcPieceIndex = newIndex
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Cache) Clean() {
 | 
			
		||||
	for _, piece := range this.pieces {
 | 
			
		||||
		piece.Clean()
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Cache) Destroy() {
 | 
			
		||||
	this.isDestroyed = true
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user