Fix cache mem size not including key size

pull/8886/head
Jason Wilder 2017-09-27 07:56:28 -06:00
parent ae821f4e2d
commit a5afaf7499
2 changed files with 9 additions and 0 deletions

View File

@ -359,6 +359,7 @@ func (c *Cache) WriteMulti(values map[string][]Value) error {
c.decreaseSize(uint64(Values(v).Size()))
}
if newKey {
addedSize += uint64(len(k))
c.increaseSize(uint64(len(k)))
}
}

View File

@ -444,6 +444,10 @@ func TestCache_Snapshot_Stats(t *testing.T) {
t.Fatal(err)
}
if got, exp := c.stats.MemSizeBytes, int64(16)+3; got != exp {
t.Fatalf("got %v, expected %v", got, exp)
}
_, err := c.Snapshot()
if err != nil {
t.Fatal(err)
@ -458,6 +462,10 @@ func TestCache_Snapshot_Stats(t *testing.T) {
if got, exp := c.stats.CachedBytes, int64(16)+3; got != exp {
t.Fatalf("got %v, expected %v", got, exp)
}
if got, exp := c.stats.MemSizeBytes, int64(16)+3; got != exp {
t.Fatalf("got %v, expected %v", got, exp)
}
}
func TestCache_CacheEmptySnapshot(t *testing.T) {