diff --git a/cache.go b/cache.go index c32881a29..e5f1163a0 100644 --- a/cache.go +++ b/cache.go @@ -54,7 +54,7 @@ type Cache interface { SetStats(s StatsClient) } -// LRUCache represents a least recently used Cache implemenation. +// LRUCache represents a least recently used Cache implementation. type LRUCache struct { cache *lru.Cache counts map[uint64]uint64 @@ -483,3 +483,35 @@ func (s *SimpleCache) Fetch(id uint64) (*Bitmap, bool) { func (s *SimpleCache) Add(id uint64, b *Bitmap) { s.cache[id] = b } + +type NopCache struct { + stats StatsClient +} + +// NopCache implement Cache interface, returns no cache for cache type None +var _ Cache = &NopCache{} + +// NewNopeCache returns a new instance of NopCache. +func NewNopCache() *NopCache { + c := &NopCache{ + stats: NopStatsClient, + } + return c +} + +func (c *NopCache) Add(id uint64, n uint64) {} +func (c *NopCache) BulkAdd(id uint64, n uint64) {} +func (c *NopCache) Get(id uint64) uint64 { return 0 } +func (c *NopCache) IDs() []uint64 { return make([]uint64, 0, 0) } + +func (c *NopCache) Invalidate() {} +func (c *NopCache) Len() int { return 0 } +func (c *NopCache) Recalculate() { +} +func (c *NopCache) SetStats(s StatsClient) { + c.stats = s +} + +func (c *NopCache) Top() []BitmapPair { + return []BitmapPair{} +} diff --git a/fragment.go b/fragment.go index 64c31434b..fdfcddd86 100644 --- a/fragment.go +++ b/fragment.go @@ -249,6 +249,8 @@ func (f *Fragment) openCache() error { f.cache = NewRankCache(f.CacheSize) case CacheTypeLRU: f.cache = NewLRUCache(f.CacheSize) + case CacheTypeNone: + f.cache = NewNopCache() default: return ErrInvalidCacheType } diff --git a/frame.go b/frame.go index 42990aeb6..d295ff01c 100644 --- a/frame.go +++ b/frame.go @@ -905,12 +905,13 @@ func (p importBitSet) Less(i, j int) bool { return p.rowIDs[i] < p.rowIDs[j] } const ( CacheTypeLRU = "lru" CacheTypeRanked = "ranked" + CacheTypeNone = "none" ) // IsValidCacheType returns true if v is a valid cache type. func IsValidCacheType(v string) bool { switch v { - case CacheTypeLRU, CacheTypeRanked: + case CacheTypeLRU, CacheTypeRanked, CacheTypeNone: return true default: return false