From d0a7fc26e11861249b3ae5a4c5ff08e6fda1a5e6 Mon Sep 17 00:00:00 2001 From: rjbasitali Date: Tue, 5 Apr 2022 04:18:49 +0500 Subject: [PATCH] refactor --- set.go | 4 +++- value.go | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/set.go b/set.go index bf58b52..bc24b13 100644 --- a/set.go +++ b/set.go @@ -1,10 +1,12 @@ package gocache +import "time" + func (cache *myCache) Set(key string, data interface{}) error { cache.mutex.Lock() defer cache.mutex.Unlock() - value := newValue(key, data, cache.expireAfter) + value := newValue(key, data, time.Now().UnixNano()+cache.expireAfter) cache.items[key] = value return nil diff --git a/value.go b/value.go index bc15281..45cf6f4 100644 --- a/value.go +++ b/value.go @@ -1,7 +1,5 @@ package gocache -import "time" - type value struct { key string data interface{} @@ -12,6 +10,6 @@ func newValue(key string, data interface{}, expiration int64) *value { return &value{ key: key, data: data, - expiration: time.Now().UnixNano() + expiration, + expiration: expiration, } }