muesli / cache2go

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

table.addedItem does not need to be a array #40

Closed ahdong2007 closed 4 years ago

ahdong2007 commented 4 years ago

if table.addedItem is set, we will remove it before we reset it. so table.addedItem will be always just one item, it didn't need to be a array. table.aboutToDeleteItem is the same.

`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 4 years ago

That's intentional. If you want to use multiple callbacks, you can use AddAddedItemCallback.