Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestCallbacks(t *testing.T) {

// add an item to the cache and setup its AboutToExpire handler
i := table.Add(k, 500*time.Millisecond, v)
i.SetAboutToExpireCallback(func(key interface{}) {
i.SetAboutToExpireCallback(func(key *CacheItem) {
m.Lock()
expired = true
m.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions cacheitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type CacheItem struct {
accessCount int64

// Callback method triggered right before removing the item from the cache
aboutToExpire func(key interface{})
aboutToExpire func(item *CacheItem)
}

// NewCacheItem returns a newly created CacheItem.
Expand Down Expand Up @@ -101,7 +101,7 @@ func (item *CacheItem) Data() interface{} {

// SetAboutToExpireCallback configures a callback, which will be called right
// before the item is about to be removed from the cache.
func (item *CacheItem) SetAboutToExpireCallback(f func(interface{})) {
func (item *CacheItem) SetAboutToExpireCallback(f func(*CacheItem)) {
item.Lock()
defer item.Unlock()
item.aboutToExpire = f
Expand Down
2 changes: 1 addition & 1 deletion cachetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (table *CacheTable) deleteInternal(key interface{}) (*CacheItem, error) {
r.RLock()
defer r.RUnlock()
if r.aboutToExpire != nil {
r.aboutToExpire(key)
r.aboutToExpire(r)
}

table.Lock()
Expand Down