mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
comment updat
This commit is contained in:
@ -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 <key> in the cache.
|
||||
// It returns -1 if the <key> 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 <key> exists in the cache.
|
||||
Contains(key interface{}) bool
|
||||
|
||||
// GetExpire retrieves and returns the expiration of <key> in the cache.
|
||||
// It returns -1 if the <key> does not exist in the cache.
|
||||
GetExpire(key interface{}) time.Duration
|
||||
|
||||
// Size returns the number of items in the cache.
|
||||
Size() (size int)
|
||||
|
||||
|
||||
@ -95,8 +95,9 @@ func newAdapterMemory(lruCap ...int) *adapterMemory {
|
||||
}
|
||||
|
||||
// Set sets cache with <key>-<value> pair, which is expired after <duration>.
|
||||
//
|
||||
// It does not expire if <duration> == 0.
|
||||
// It deletes the <key> if <duration> < 0 or given <value> is nil.
|
||||
// It deletes the <key> if <duration> < 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 <key> without changing its expiration and returns the old value.
|
||||
// The returned <exist> value is false if the <key> does not exist in the cache.
|
||||
// The returned value <exist> is false if the <key> 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 <key>.
|
||||
// GetExpire retrieves and returns the expiration of <key> in the cache.
|
||||
// It returns -1 if the <key> does not exist in the cache.
|
||||
func (c *adapterMemory) GetExpire(key interface{}) time.Duration {
|
||||
c.dataMu.RLock()
|
||||
|
||||
Reference in New Issue
Block a user