lib/ignore: Store cache timestamps as Unix ns counts (#7326)

This commit is contained in:
greatroar 2021-02-04 18:39:06 +01:00 committed by GitHub
parent 070bf3b776
commit 31119ed61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ type cache struct {
type cacheEntry struct {
result Result
access time.Time
access int64 // Unix nanosecond count. Sufficient until the year 2262.
}
func newCache(patterns []Pattern) *cache {
@ -33,7 +33,7 @@ func newCache(patterns []Pattern) *cache {
func (c *cache) clean(d time.Duration) {
for k, v := range c.entries {
if clock.Now().Sub(v.access) > d {
if clock.Now().Sub(time.Unix(0, v.access)) > d {
delete(c.entries, k)
}
}
@ -42,14 +42,14 @@ func (c *cache) clean(d time.Duration) {
func (c *cache) get(key string) (Result, bool) {
entry, ok := c.entries[key]
if ok {
entry.access = clock.Now()
entry.access = clock.Now().UnixNano()
c.entries[key] = entry
}
return entry.result, ok
}
func (c *cache) set(key string, result Result) {
c.entries[key] = cacheEntry{result, time.Now()}
c.entries[key] = cacheEntry{result, time.Now().UnixNano()}
}
func (c *cache) len() int {