mirror of https://github.com/rjbasitali/go-cache
refactor
parent
9242ee35fe
commit
d0a7fc26e1
4
set.go
4
set.go
|
|
@ -1,10 +1,12 @@
|
||||||
package gocache
|
package gocache
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
func (cache *myCache) Set(key string, data interface{}) error {
|
func (cache *myCache) Set(key string, data interface{}) error {
|
||||||
cache.mutex.Lock()
|
cache.mutex.Lock()
|
||||||
defer cache.mutex.Unlock()
|
defer cache.mutex.Unlock()
|
||||||
|
|
||||||
value := newValue(key, data, cache.expireAfter)
|
value := newValue(key, data, time.Now().UnixNano()+cache.expireAfter)
|
||||||
cache.items[key] = value
|
cache.items[key] = value
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
4
value.go
4
value.go
|
|
@ -1,7 +1,5 @@
|
||||||
package gocache
|
package gocache
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type value struct {
|
type value struct {
|
||||||
key string
|
key string
|
||||||
data interface{}
|
data interface{}
|
||||||
|
|
@ -12,6 +10,6 @@ func newValue(key string, data interface{}, expiration int64) *value {
|
||||||
return &value{
|
return &value{
|
||||||
key: key,
|
key: key,
|
||||||
data: data,
|
data: data,
|
||||||
expiration: time.Now().UnixNano() + expiration,
|
expiration: expiration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue