|
|
@ -36,49 +36,49 @@ func NewIndexCacheBase(max int) *IndexCacheBase {
|
|
|
|
return &IndexCacheBase{maxSize: max, data: make(map[interface{}]*dataobj.TsdbItem)}
|
|
|
|
return &IndexCacheBase{maxSize: max, data: make(map[interface{}]*dataobj.TsdbItem)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexCacheBase) Put(key interface{}, item *dataobj.TsdbItem) {
|
|
|
|
func (i *IndexCacheBase) Put(key interface{}, item *dataobj.TsdbItem) {
|
|
|
|
this.Lock()
|
|
|
|
i.Lock()
|
|
|
|
defer this.Unlock()
|
|
|
|
defer i.Unlock()
|
|
|
|
this.data[key] = item
|
|
|
|
i.data[key] = item
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexCacheBase) Get(key interface{}) *dataobj.TsdbItem {
|
|
|
|
func (i *IndexCacheBase) Get(key interface{}) *dataobj.TsdbItem {
|
|
|
|
this.RLock()
|
|
|
|
i.RLock()
|
|
|
|
defer this.RUnlock()
|
|
|
|
defer i.RUnlock()
|
|
|
|
return this.data[key]
|
|
|
|
return i.data[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexCacheBase) ContainsKey(key interface{}) bool {
|
|
|
|
func (i *IndexCacheBase) ContainsKey(key interface{}) bool {
|
|
|
|
this.RLock()
|
|
|
|
i.RLock()
|
|
|
|
defer this.RUnlock()
|
|
|
|
defer i.RUnlock()
|
|
|
|
return this.data[key] != nil
|
|
|
|
return i.data[key] != nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexCacheBase) Size() int {
|
|
|
|
func (i *IndexCacheBase) Size() int {
|
|
|
|
this.RLock()
|
|
|
|
i.RLock()
|
|
|
|
defer this.RUnlock()
|
|
|
|
defer i.RUnlock()
|
|
|
|
return len(this.data)
|
|
|
|
return len(i.data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexCacheBase) Keys() []interface{} {
|
|
|
|
func (i *IndexCacheBase) Keys() []interface{} {
|
|
|
|
this.RLock()
|
|
|
|
i.RLock()
|
|
|
|
defer this.RUnlock()
|
|
|
|
defer i.RUnlock()
|
|
|
|
|
|
|
|
|
|
|
|
count := len(this.data)
|
|
|
|
count := len(i.data)
|
|
|
|
if count == 0 {
|
|
|
|
if count == 0 {
|
|
|
|
return []interface{}{}
|
|
|
|
return []interface{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
keys := make([]interface{}, 0, count)
|
|
|
|
keys := make([]interface{}, 0, count)
|
|
|
|
for key := range this.data {
|
|
|
|
for key := range i.data {
|
|
|
|
keys = append(keys, key)
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return keys
|
|
|
|
return keys
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexCacheBase) Remove(key interface{}) {
|
|
|
|
func (i *IndexCacheBase) Remove(key interface{}) {
|
|
|
|
this.Lock()
|
|
|
|
i.Lock()
|
|
|
|
defer this.Unlock()
|
|
|
|
defer i.Unlock()
|
|
|
|
delete(this.data, key)
|
|
|
|
delete(i.data, key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|