muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters
Other
2.11k stars 518 forks source link

Question about SetAddedItemCallback #33

Closed NicholasLiuWei closed 5 years ago

NicholasLiuWei commented 5 years ago

hello 请看如下函数,是不是应该将这这段注释掉 func (table CacheTable) SetAddedItemCallback(f func(CacheItem)) {

//if len(table.addedItem) > 0 {
//  table.RemoveAddedItemCallbacks()
//}
table.Lock()
defer table.Unlock()
table.addedItem = append(table.addedItem, f)

}

muesli commented 5 years ago

Please be aware that we only speak English in this repo. From what I can gather, you're suggesting to remove the first three lines? What's the reasoning behind it?

DoubleChuang commented 5 years ago

hello 请看如下函数,是不是应该将这这段注释掉 func (table CacheTable) SetAddedItemCallback(f func(CacheItem)) {

//if len(table.addedItem) > 0 {
//    table.RemoveAddedItemCallbacks()
//}
table.Lock()
defer table.Unlock()
table.addedItem = append(table.addedItem, f)

}

Because there is already an AddAddedItemCallback, SetAddedItemCallback is used to replace the current call back function

因為SetAddedItemCallback 是用來取代 當下設定的 回調函式 如果把那三行註解了就跟AddAddedItemCallback函式一樣 是用來增加函式到回調函式列表

muesli commented 5 years ago

So I guess we can close this one.