File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,16 @@ type Item struct {
17
17
Expiration time.Time
18
18
}
19
19
20
- // Returns true if the item has expired.
21
- func (item Item ) Expired () bool {
20
+ func (item Item ) expired (now time.Time ) bool {
22
21
if item .Expiration == emptyTime {
23
22
return false
24
23
}
25
- return item .Expiration .Before (time .Now ())
24
+ return item .Expiration .Before (now )
25
+ }
26
+
27
+ // Returns true if the item has expired.
28
+ func (item Item ) Expired () bool {
29
+ return item .expired (time .Now ())
26
30
}
27
31
28
32
const (
@@ -868,9 +872,10 @@ type keyAndValue struct {
868
872
// Delete all expired items from the cache.
869
873
func (c * cache ) DeleteExpired () {
870
874
var evictedItems []keyAndValue
875
+ now := time .Now ()
871
876
c .mu .Lock ()
872
877
for k , v := range c .items {
873
- if v .Expired ( ) {
878
+ if v .expired ( now ) {
874
879
ov , evicted := c .delete (k )
875
880
if evicted {
876
881
evictedItems = append (evictedItems , keyAndValue {k , ov })
You can’t perform that action at this time.
0 commit comments