From 4b065029af63c16ffd754ac28190ba4b3125c494 Mon Sep 17 00:00:00 2001 From: vince Date: Tue, 25 Aug 2020 10:43:42 +0800 Subject: Implement cache eviction and testing --- cache/lru_id_cache.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'cache/lru_id_cache.go') diff --git a/cache/lru_id_cache.go b/cache/lru_id_cache.go index e31f2843..a387cb75 100644 --- a/cache/lru_id_cache.go +++ b/cache/lru_id_cache.go @@ -9,20 +9,16 @@ import ( type LRUIdCache struct { parentCache *lru.Cache maxSize int - onEvict func(id entity.Id) } -func NewLRUIdCache(size int, onEvicted func(id entity.Id)) (*LRUIdCache, error) { - cache, err := lru.New(size) - if err != nil { - return nil, err - } +func NewLRUIdCache(size int) *LRUIdCache { + // Ignore error here + cache, _ := lru.New(size) return &LRUIdCache{ cache, size, - onEvicted, - }, nil + } } func (c *LRUIdCache) Add(id entity.Id) bool { @@ -60,5 +56,6 @@ func (c *LRUIdCache) Remove(id entity.Id) bool { } func (c *LRUIdCache) Resize(size int) int { + c.maxSize = size return c.parentCache.Resize(size) } -- cgit