implement nopcache

This commit is contained in:
Linh Vo 2017-07-20 16:11:13 -05:00
parent 2e5405573b
commit f68362c40c
3 changed files with 37 additions and 2 deletions

View file

@ -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{}
}

View file

@ -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
}

View file

@ -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