(hash string)
| 199 | } |
| 200 | |
| 201 | func (this *MemoryList) Remove(hash string) error { |
| 202 | this.locker.Lock() |
| 203 | |
| 204 | itemMap, ok := this.itemMaps[this.prefix(hash)] |
| 205 | if !ok { |
| 206 | this.locker.Unlock() |
| 207 | return nil |
| 208 | } |
| 209 | |
| 210 | item, ok := itemMap[hash] |
| 211 | if ok { |
| 212 | if this.onRemove != nil { |
| 213 | this.onRemove(item) |
| 214 | } |
| 215 | |
| 216 | atomic.AddInt64(&this.count, -1) |
| 217 | delete(itemMap, hash) |
| 218 | } |
| 219 | |
| 220 | this.locker.Unlock() |
| 221 | return nil |
| 222 | } |
| 223 | |
| 224 | // Purge 清理过期的缓存 |
| 225 | // count 每次遍历的最大数量,控制此数字可以保证每次清理的时候不用花太多时间 |