File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,26 @@ func TestDeleteExpired(t *testing.T) {
123
123
t .Errorf ("want2 %d items but got2 %d" , want2 , got2 )
124
124
}
125
125
})
126
+
127
+ t .Run ("issue #51" , func (t * testing.T ) {
128
+ defer restore ()
129
+ c := New [string , int ]()
130
+
131
+ c .Set ("1" , 10 , WithExpiration (10 * time .Millisecond ))
132
+ c .Set ("2" , 20 , WithExpiration (20 * time .Millisecond ))
133
+ c .Set ("1" , 30 , WithExpiration (100 * time .Millisecond )) // expected do not expired key "1"
134
+
135
+ nowFunc = func () time.Time {
136
+ return now .Add (30 * time .Millisecond ).Add (time .Millisecond )
137
+ }
138
+
139
+ c .DeleteExpired ()
140
+
141
+ got := c .Len ()
142
+ if want := 1 ; want != got {
143
+ t .Errorf ("want %d items but got %d" , want , got )
144
+ }
145
+ })
126
146
}
127
147
128
148
func max (x , y int ) int {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ func newExpirationManager[K comparable]() *expirationManager[K] {
21
21
22
22
func (m * expirationManager [K ]) update (key K , expiration time.Time ) {
23
23
if e , ok := m .mapping [key ]; ok {
24
+ e .expiration = expiration
24
25
heap .Fix (& m .queue , e .index )
25
26
} else {
26
27
v := & expirationKey [K ]{
You can’t perform that action at this time.
0 commit comments