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

Function TestCacheRestStats

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

Source from the content-addressed store, hash-verified

671}
672
673func TestCacheRestStats(t *testing.T) {
674 t.Parallel()
675
676 // given
677 cache, _ := New(context.Background(), Config{
678 Shards: 8,
679 LifeWindow: time.Second,
680 MaxEntriesInWindow: 1,
681 MaxEntrySize: 256,
682 })
683
684 // when
685 for i := 0; i < 100; i++ {
686 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
687 }
688
689 for i := 0; i < 10; i++ {
690 value, err := cache.Get(fmt.Sprintf("key%d", i))
691 noError(t, err)
692 assertEqual(t, string(value), "value")
693 }
694 for i := 100; i < 110; i++ {
695 _, err := cache.Get(fmt.Sprintf("key%d", i))
696 assertEqual(t, ErrEntryNotFound, err)
697 }
698 for i := 10; i < 20; i++ {
699 err := cache.Delete(fmt.Sprintf("key%d", i))
700 noError(t, err)
701 }
702 for i := 110; i < 120; i++ {
703 err := cache.Delete(fmt.Sprintf("key%d", i))
704 assertEqual(t, ErrEntryNotFound, err)
705 }
706
707 stats := cache.Stats()
708 assertEqual(t, stats.Hits, int64(10))
709 assertEqual(t, stats.Misses, int64(10))
710 assertEqual(t, stats.DelHits, int64(10))
711 assertEqual(t, stats.DelMisses, int64(10))
712
713 //then
714 cache.ResetStats()
715 stats = cache.Stats()
716 assertEqual(t, stats.Hits, int64(0))
717 assertEqual(t, stats.Misses, int64(0))
718 assertEqual(t, stats.DelHits, int64(0))
719 assertEqual(t, stats.DelMisses, int64(0))
720}
721
722func TestCacheDel(t *testing.T) {
723 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
SetMethod · 0.80
DeleteMethod · 0.80
StatsMethod · 0.80
ResetStatsMethod · 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…