muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

table.addedItem does not need to be a array

ahdong2007 opened this issue · comments

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)

}`

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