From b1291d9dbe1477d17c8a222f46f985e1ea9db850 Mon Sep 17 00:00:00 2001 From: Durand Fabrice Date: Wed, 3 Jan 2018 09:44:03 -0500 Subject: [PATCH 1/2] Delete from the cache on Get if the item expired (to trigger onEvicted) --- cache.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cache.go b/cache.go index db88d2f..35aa7dd 100644 --- a/cache.go +++ b/cache.go @@ -128,6 +128,7 @@ func (c *cache) Get(k string) (interface{}, bool) { if item.Expiration > 0 { if time.Now().UnixNano() > item.Expiration { c.mu.RUnlock() + c.Delete(k) return nil, false } } From cf0198ac7d92634998b3f3f2b616553fda07d7b0 Mon Sep 17 00:00:00 2001 From: Durand Fabrice Date: Thu, 4 Jan 2018 09:39:16 -0500 Subject: [PATCH 2/2] Also added in GetWithExpiration --- cache.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cache.go b/cache.go index 35aa7dd..91a72e8 100644 --- a/cache.go +++ b/cache.go @@ -152,6 +152,7 @@ func (c *cache) GetWithExpiration(k string) (interface{}, time.Time, bool) { if item.Expiration > 0 { if time.Now().UnixNano() > item.Expiration { c.mu.RUnlock() + c.Delete(k) return nil, time.Time{}, false }