优化HTTP缓存,主要是并发冲突、缓存写入不全等问题

This commit is contained in:
刘祥超
2021-06-06 23:42:11 +08:00
parent 0df5dfad23
commit a49b724745
18 changed files with 299 additions and 103 deletions

View File

@@ -33,6 +33,16 @@ func (this *MemoryList) Reset() error {
func (this *MemoryList) Add(hash string, item *Item) error {
this.locker.Lock()
// 先删除,为了可以正确触发统计
oldItem, ok := this.m[hash]
if ok {
if this.onRemove != nil {
this.onRemove(oldItem)
}
}
// 添加
if this.onAdd != nil {
this.onAdd(item)
}