MCPcopy Create free account
hub / github.com/allegro/bigcache / TestCacheStats

Function TestCacheStats

bigcache_test.go:608–648  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

606}
607
608func TestCacheStats(t *testing.T) {
609 t.Parallel()
610
611 // given
612 cache, _ := New(context.Background(), Config{
613 Shards: 8,
614 LifeWindow: time.Second,
615 MaxEntriesInWindow: 1,
616 MaxEntrySize: 256,
617 })
618
619 // when
620 for i := 0; i < 100; i++ {
621 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
622 }
623
624 for i := 0; i < 10; i++ {
625 value, err := cache.Get(fmt.Sprintf("key%d", i))
626 noError(t, err)
627 assertEqual(t, string(value), "value")
628 }
629 for i := 100; i < 110; i++ {
630 _, err := cache.Get(fmt.Sprintf("key%d", i))
631 assertEqual(t, ErrEntryNotFound, err)
632 }
633 for i := 10; i < 20; i++ {
634 err := cache.Delete(fmt.Sprintf("key%d", i))
635 noError(t, err)
636 }
637 for i := 110; i < 120; i++ {
638 err := cache.Delete(fmt.Sprintf("key%d", i))
639 assertEqual(t, ErrEntryNotFound, err)
640 }
641
642 // then
643 stats := cache.Stats()
644 assertEqual(t, stats.Hits, int64(10))
645 assertEqual(t, stats.Misses, int64(10))
646 assertEqual(t, stats.DelHits, int64(10))
647 assertEqual(t, stats.DelMisses, int64(10))
648}
649func TestCacheEntryStats(t *testing.T) {
650 t.Parallel()
651

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
SetMethod · 0.80
DeleteMethod · 0.80
StatsMethod · 0.80
noErrorFunction · 0.70
assertEqualFunction · 0.70
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…