diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 273a872..413ceb4 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -1156,11 +1156,16 @@ func (this *FileStorage) purgeLoop() { // 热点数据任务 func (this *FileStorage) hotLoop() { - var memoryStorage = this.memoryStorage + var memoryStorage = this.memoryStorage // copy if memoryStorage == nil { return } + // check memory space size + if !memoryStorage.HasFreeSpaceForHotItems() { + return + } + this.hotMapLocker.Lock() if len(this.hotMap) == 0 { this.hotMapLocker.Unlock() diff --git a/internal/caches/storage_memory.go b/internal/caches/storage_memory.go index ba4af46..65d9678 100644 --- a/internal/caches/storage_memory.go +++ b/internal/caches/storage_memory.go @@ -400,6 +400,11 @@ func (this *MemoryStorage) CanSendfile() bool { return false } +// HasFreeSpaceForHotItems 是否有足够的空间提供给热门内容 +func (this *MemoryStorage) HasFreeSpaceForHotItems() bool { + return atomic.LoadInt64(&this.usedSize) < this.memoryCapacityBytes()*3/4 +} + // 计算Key Hash func (this *MemoryStorage) hash(key string) uint64 { return xxhash.Sum64String(key)