From 6de6095c33fe8b03c2766d0035a906aee92e4417 Mon Sep 17 00:00:00 2001 From: xiehuc Date: Wed, 27 Mar 2019 17:27:02 +0800 Subject: [PATCH] change callback arg --- cache_test.go | 2 +- cacheitem.go | 4 ++-- cachetable.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cache_test.go b/cache_test.go index 8d0893f..0eebfb6 100644 --- a/cache_test.go +++ b/cache_test.go @@ -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() diff --git a/cacheitem.go b/cacheitem.go index eb72bc2..0c676c3 100644 --- a/cacheitem.go +++ b/cacheitem.go @@ -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. @@ -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 diff --git a/cachetable.go b/cachetable.go index 1e2d7d3..6fb5f8c 100644 --- a/cachetable.go +++ b/cachetable.go @@ -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()