MCPcopy Create free account
hub / github.com/patrickmn/go-cache / TestCacheTimes

Function TestCacheTimes

cache_test.go:71–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestCacheTimes(t *testing.T) {
72 var found bool
73
74 tc := New(50*time.Millisecond, 1*time.Millisecond)
75 tc.Set("a", 1, DefaultExpiration)
76 tc.Set("b", 2, NoExpiration)
77 tc.Set("c", 3, 20*time.Millisecond)
78 tc.Set("d", 4, 70*time.Millisecond)
79
80 <-time.After(25 * time.Millisecond)
81 _, found = tc.Get("c")
82 if found {
83 t.Error("Found c when it should have been automatically deleted")
84 }
85
86 <-time.After(30 * time.Millisecond)
87 _, found = tc.Get("a")
88 if found {
89 t.Error("Found a when it should have been automatically deleted")
90 }
91
92 _, found = tc.Get("b")
93 if !found {
94 t.Error("Did not find b even though it was set to never expire")
95 }
96
97 _, found = tc.Get("d")
98 if !found {
99 t.Error("Did not find d even though it was set to expire later than the default")
100 }
101
102 <-time.After(20 * time.Millisecond)
103 _, found = tc.Get("d")
104 if found {
105 t.Error("Found d when it should have been automatically deleted (later than the default)")
106 }
107}
108
109func TestNewFrom(t *testing.T) {
110 m := map[string]Item{

Callers

nothing calls this directly

Calls 3

NewFunction · 0.85
SetMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…