diff --git a/os/gcache/gcache_adapter.go b/os/gcache/gcache_adapter.go index 1131e5d42..944735191 100644 --- a/os/gcache/gcache_adapter.go +++ b/os/gcache/gcache_adapter.go @@ -66,6 +66,10 @@ type Adapter interface { // safety purpose. GetOrSetFuncLock(key interface{}, f func() interface{}, duration time.Duration) interface{} + // GetExpire retrieves and returns the expiration of in the cache. + // It returns -1 if the does not exist in the cache. + GetExpire(key interface{}) time.Duration + // Remove deletes one or more keys from cache, and returns its value. // If multiple keys are given, it returns the value of the last deleted item. Remove(keys ...interface{}) (value interface{}) @@ -81,10 +85,6 @@ type Adapter interface { // Contains checks and returns whether given exists in the cache. Contains(key interface{}) bool - // GetExpire retrieves and returns the expiration of in the cache. - // It returns -1 if the does not exist in the cache. - GetExpire(key interface{}) time.Duration - // Size returns the number of items in the cache. Size() (size int) diff --git a/os/gcache/gcache_adapter_memory.go b/os/gcache/gcache_adapter_memory.go index 7bfe36f80..e606401e9 100644 --- a/os/gcache/gcache_adapter_memory.go +++ b/os/gcache/gcache_adapter_memory.go @@ -95,8 +95,9 @@ func newAdapterMemory(lruCap ...int) *adapterMemory { } // Set sets cache with - pair, which is expired after . +// // It does not expire if == 0. -// It deletes the if < 0 or given is nil. +// It deletes the if < 0. func (c *adapterMemory) Set(key interface{}, value interface{}, duration time.Duration) { expireTime := c.getInternalExpire(duration) c.dataMu.Lock() @@ -112,7 +113,7 @@ func (c *adapterMemory) Set(key interface{}, value interface{}, duration time.Du } // Update updates the value of without changing its expiration and returns the old value. -// The returned value is false if the does not exist in the cache. +// The returned value is false if the does not exist in the cache. func (c *adapterMemory) Update(key interface{}, value interface{}) (oldValue interface{}, exist bool) { c.dataMu.Lock() defer c.dataMu.Unlock() @@ -146,7 +147,7 @@ func (c *adapterMemory) UpdateExpire(key interface{}, duration time.Duration) (o return -1 } -// GetExpire retrieves and returns the expiration of . +// GetExpire retrieves and returns the expiration of in the cache. // It returns -1 if the does not exist in the cache. func (c *adapterMemory) GetExpire(key interface{}) time.Duration { c.dataMu.RLock()