From 028539f10da8d27e0aa81d27e79214322c357544 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Fri, 17 Feb 2017 15:18:38 -0500 Subject: [PATCH] top bug in cache refresh --- cache.go | 16 +++++++++++----- fragment.go | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cache.go b/cache.go index a1cba3dec..fb5f4defd 100644 --- a/cache.go +++ b/cache.go @@ -22,6 +22,7 @@ type Cache interface { // Updates the cache, if necessary. Invalidate() + Refresh() // Returns an ordered list of the top ranked bitmaps. Top() []BitmapPair @@ -86,6 +87,8 @@ func (c *LRUCache) Top() []BitmapPair { } func (c *LRUCache) onEvicted(key lru.Key, _ interface{}) { delete(c.counts, key.(uint64)) } +func (c *LRUCache) Refresh() { +} // Ensure LRUCache implements Cache. var _ Cache = &LRUCache{} @@ -117,17 +120,17 @@ func (c *RankCache) Add(bitmapID uint64, n uint64) { return } - // Add to cache. c.entries[bitmapID] = n + // If size is larger than the threshold then trim it. if len(c.entries) > c.ThresholdLength { c.update() - for id, n := range c.entries { - if n <= c.ThresholdValue { - delete(c.entries, id) + for id, n := range c.entries { + if n <= c.ThresholdValue { + delete(c.entries, id) + } } - } } } @@ -154,6 +157,9 @@ func (c *RankCache) Invalidate() { c.update() } } +func (c *RankCache) Refresh() { + c.update() +} // update reorders the entries by rank. func (c *RankCache) update() { diff --git a/fragment.go b/fragment.go index 88b39663c..51cb1dc61 100644 --- a/fragment.go +++ b/fragment.go @@ -909,7 +909,7 @@ func (f *Fragment) Import(bitmapIDs, profileIDs []uint64) error { f.cache.Add(bitmapID, f.bitmap(bitmapID).Count()) } - f.cache.Invalidate() + f.cache.Refresh() return nil }(); err != nil { _ = f.closeStorage()