@@ -14,23 +14,23 @@ var emptyTime = time.Time{}
14
14
15
15
type Item struct {
16
16
Object interface {}
17
- Expiration time. Time
17
+ Expiration int64
18
18
}
19
19
20
- func (item Item ) expired (now time. Time ) bool {
21
- if item .Expiration == emptyTime {
20
+ func (item Item ) expired (now int64 ) bool {
21
+ if item .Expiration == 0 {
22
22
return false
23
23
}
24
- return item .Expiration . Before ( now )
24
+ return now > item .Expiration
25
25
}
26
26
27
27
// Returns true if the item has expired.
28
28
func (item Item ) Expired () bool {
29
29
// "Inlining" of expired
30
- if item .Expiration == emptyTime {
30
+ if item .Expiration == 0 {
31
31
return false
32
32
}
33
- return item . Expiration . Before ( time .Now ())
33
+ return time .Now (). UnixNano () > item . Expiration
34
34
}
35
35
36
36
const (
@@ -67,12 +67,12 @@ func (c *cache) Set(k string, x interface{}, d time.Duration) {
67
67
}
68
68
69
69
func (c * cache ) set (k string , x interface {}, d time.Duration ) {
70
- e := emptyTime
70
+ var e int64
71
71
if d == DefaultExpiration {
72
72
d = c .defaultExpiration
73
73
}
74
74
if d > 0 {
75
- e = time .Now ().Add (d )
75
+ e = time .Now ().Add (d ). UnixNano ()
76
76
}
77
77
c .items [k ] = Item {
78
78
Object : x ,
@@ -881,7 +881,7 @@ type keyAndValue struct {
881
881
// Delete all expired items from the cache.
882
882
func (c * cache ) DeleteExpired () {
883
883
var evictedItems []keyAndValue
884
- now := time .Now ()
884
+ now := time .Now (). UnixNano ()
885
885
c .mu .Lock ()
886
886
for k , v := range c .items {
887
887
if v .expired (now ) {
0 commit comments