File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -998,19 +998,25 @@ func (c *cache) LoadFile(fname string) error {
998
998
return fp .Close ()
999
999
}
1000
1000
1001
- // Returns the items in the cache. This may include items that have expired,
1002
- // but have not yet been cleaned up. If this is significant, the Expiration
1003
- // fields of the items should be checked. Note that explicit synchronization
1004
- // is needed to use a cache and its corresponding Items() return value at
1005
- // the same time, as the map is shared.
1001
+ // Copies all unexpired items in the cache into a new map and returns it.
1006
1002
func (c * cache ) Items () map [string ]Item {
1007
1003
c .mu .RLock ()
1008
1004
defer c .mu .RUnlock ()
1009
- return c .items
1005
+ m := make (map [string ]Item , len (c .items ))
1006
+ now := time .Now ().UnixNano ()
1007
+ for k , v := range c .items {
1008
+ if v .Expiration > 0 {
1009
+ if now > v .Expiration {
1010
+ continue
1011
+ }
1012
+ }
1013
+ m [k ] = v
1014
+ }
1015
+ return m
1010
1016
}
1011
1017
1012
1018
// Returns the number of items in the cache. This may include items that have
1013
- // expired, but have not yet been cleaned up. Equivalent to len(c.Items()).
1019
+ // expired, but have not yet been cleaned up.
1014
1020
func (c * cache ) ItemCount () int {
1015
1021
c .mu .RLock ()
1016
1022
n := len (c .items )
You can’t perform that action at this time.
0 commit comments