diff --git a/cache2go/cache.go b/cache2go/cache.go index cb3bf66ee..d24b36f2c 100644 --- a/cache2go/cache.go +++ b/cache2go/cache.go @@ -114,6 +114,10 @@ func CachePush(key string, val interface{}) { if !found { elements = append(elements, val) } + if _, ok := cache[key]; !ok { + // only count if the key is not already there + count(key) + } cache[key] = timestampedValue{time.Now(), elements} } else { transactionBuffer = append(transactionBuffer, transactionItem{key: key, value: val, kind: KIND_ADP}) @@ -174,18 +178,6 @@ func RemPrefixKey(prefix string) { } } -func GetAllEntries(prefix string) map[string]interface{} { - mux.RLock() - defer mux.RUnlock() - result := make(map[string]interface{}) - for key, timestampedValue := range cache { - if strings.HasPrefix(key, prefix) { - result[key] = timestampedValue.value - } - } - return result -} - // Delete all keys from cache func Flush() { mux.Lock() @@ -228,6 +220,18 @@ func descount(key string) { } } +func GetAllEntries(prefix string) map[string]interface{} { + mux.RLock() + defer mux.RUnlock() + result := make(map[string]interface{}) + for key, timestampedValue := range cache { + if strings.HasPrefix(key, prefix) { + result[key] = timestampedValue.value + } + } + return result +} + func GetEntriesKeys(prefix string) (keys []string) { mux.RLock() defer mux.RUnlock()