| 339 | } |
| 340 | |
| 341 | func (this *MemoryList) Stat(check func(hash string) bool) (*Stat, error) { |
| 342 | this.locker.RLock() |
| 343 | defer this.locker.RUnlock() |
| 344 | |
| 345 | result := &Stat{ |
| 346 | Count: 0, |
| 347 | Size: 0, |
| 348 | } |
| 349 | for _, itemMap := range this.itemMaps { |
| 350 | for hash, item := range itemMap { |
| 351 | if !item.IsExpired() { |
| 352 | // 检查文件是否存在、内容是否正确等 |
| 353 | if check != nil && check(hash) { |
| 354 | result.Count++ |
| 355 | result.ValueSize += item.Size() |
| 356 | result.Size += item.TotalSize() |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | return result, nil |
| 362 | } |
| 363 | |
| 364 | // Count 总数量 |
| 365 | func (this *MemoryList) Count() (int64, error) { |