mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
implement nopcache
This commit is contained in:
parent
2e5405573b
commit
f68362c40c
3 changed files with 37 additions and 2 deletions
34
cache.go
34
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{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
3
frame.go
3
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue