From afadf13f9f1c09f0c5e1b080662aa93cc12c5141 Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Mon, 30 Nov 2015 15:12:19 -0500 Subject: [PATCH] Back to UnixNano(), syscall dependency isn't worth a few nanoseconds better performance --- cache.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/cache.go b/cache.go index a573611..4f44ba2 100644 --- a/cache.go +++ b/cache.go @@ -7,7 +7,6 @@ import ( "os" "runtime" "sync" - "syscall" "time" ) @@ -21,9 +20,7 @@ func (item Item) Expired() bool { if item.Expiration == 0 { return false } - var tv syscall.Timeval - syscall.Gettimeofday(&tv) - return tv.Nano() > item.Expiration + return time.Now().UnixNano() > item.Expiration } const ( @@ -112,9 +109,7 @@ func (c *cache) Get(k string) (interface{}, bool) { return nil, false } if item.Expiration > 0 { - var tv syscall.Timeval - syscall.Gettimeofday(&tv) - if tv.Nano() > item.Expiration { + if time.Now().UnixNano() > item.Expiration { c.mu.RUnlock() return nil, false } @@ -130,9 +125,7 @@ func (c *cache) get(k string) (interface{}, bool) { } // "Inlining" of Expired if item.Expiration > 0 { - var tv syscall.Timeval - syscall.Gettimeofday(&tv) - if tv.Nano() > item.Expiration { + if time.Now().UnixNano() > item.Expiration { c.mu.RUnlock() return nil, false } @@ -890,12 +883,8 @@ type keyAndValue struct { // Delete all expired items from the cache. func (c *cache) DeleteExpired() { - var ( - evictedItems []keyAndValue - tv syscall.Timeval - ) - syscall.Gettimeofday(&tv) - now := tv.Nano() + var evictedItems []keyAndValue + now := time.Now().UnixNano() c.mu.Lock() for k, v := range c.items { // "Inlining" of expired