diff --git a/g/os/gcache/gcache.go b/g/os/gcache/gcache.go index 8815b4da7..3123c73d2 100644 --- a/g/os/gcache/gcache.go +++ b/g/os/gcache/gcache.go @@ -10,21 +10,30 @@ package gcache // Default cache object. var cache = New() -// Set sets cache with - pair, which is expired after milliseconds. -// If <=0 means it does not expire. +// Set sets cache with - pair, which is expired after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func Set(key interface{}, value interface{}, duration interface{}) { cache.Set(key, value, duration) } // SetIfNotExist sets cache with - pair if does not exist in the cache, -// which is expired after milliseconds. -// If <=0 means it does not expire. +// which is expired after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func SetIfNotExist(key interface{}, value interface{}, duration interface{}) bool { return cache.SetIfNotExist(key, value, duration) } -// Sets batch sets cache with key-value pairs by , which is expired after milliseconds. -// If <=0 means it does not expire. +// Sets batch sets cache with key-value pairs by , which is expired after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func Sets(data map[interface{}]interface{}, duration interface{}) { cache.Sets(data, duration) } @@ -37,8 +46,11 @@ func Get(key interface{}) interface{} { // GetOrSet returns the value of , // or sets - pair and returns if does not exist in the cache. -// The key-value pair expires after milliseconds. -// If <=0 means it does not expire. +// The key-value pair expires after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func GetOrSet(key interface{}, value interface{}, duration interface{}) interface{} { return cache.GetOrSet(key, value, duration) } @@ -46,8 +58,11 @@ func GetOrSet(key interface{}, value interface{}, duration interface{}) interfac // GetOrSetFunc returns the value of , // or sets with result of function and returns its result // if does not exist in the cache. -// The key-value pair expires after milliseconds. -// If <=0 means it does not expire. +// The key-value pair expires after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func GetOrSetFunc(key interface{}, f func() interface{}, duration interface{}) interface{} { return cache.GetOrSetFunc(key, f, duration) } @@ -55,8 +70,11 @@ func GetOrSetFunc(key interface{}, f func() interface{}, duration interface{}) i // GetOrSetFuncLock returns the value of , // or sets with result of function and returns its result // if does not exist in the cache. -// The key-value pair expires after milliseconds. -// If <=0 means it does not expire. +// The key-value pair expires after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. // // Note that the function is executed within writing mutex lock. func GetOrSetFuncLock(key interface{}, f func() interface{}, duration interface{}) interface{} { diff --git a/g/os/gcache/gcache_mem_cache.go b/g/os/gcache/gcache_mem_cache.go index 976d2c5a1..35f81cf75 100644 --- a/g/os/gcache/gcache_mem_cache.go +++ b/g/os/gcache/gcache_mem_cache.go @@ -115,8 +115,11 @@ func (c *memCache) getMilliExpire(duration interface{}) int { } } -// Set sets cache with - pair, which is expired after milliseconds. -// If <=0 means it does not expire. +// Set sets cache with - pair, which is expired after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func (c *memCache) Set(key interface{}, value interface{}, duration interface{}) { expire := c.getMilliExpire(duration) expireTime := c.getInternalExpire(expire) @@ -127,8 +130,11 @@ func (c *memCache) Set(key interface{}, value interface{}, duration interface{}) } // doSetWithLockCheck sets cache with - pair if does not exist in the cache, -// which is expired after milliseconds. -// If <=0 means it does not expire. +// which is expired after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. // // It doubly checks the whether exists in the cache using mutex writing lock // before setting it to the cache. @@ -161,8 +167,11 @@ func (c *memCache) getInternalExpire(expire int) int64 { } // SetIfNotExist sets cache with - pair if does not exist in the cache, -// which is expired after milliseconds. -// If <=0 means it does not expire. +// which is expired after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func (c *memCache) SetIfNotExist(key interface{}, value interface{}, duration interface{}) bool { expire := c.getMilliExpire(duration) if !c.Contains(key) { @@ -172,8 +181,11 @@ func (c *memCache) SetIfNotExist(key interface{}, value interface{}, duration in return false } -// Sets batch sets cache with key-value pairs by , which is expired after milliseconds. -// If <=0 means it does not expire. +// Sets batch sets cache with key-value pairs by , which is expired after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func (c *memCache) Sets(data map[interface{}]interface{}, duration interface{}) { expire := c.getMilliExpire(duration) expireTime := c.getInternalExpire(expire) @@ -203,8 +215,11 @@ func (c *memCache) Get(key interface{}) interface{} { // GetOrSet returns the value of , // or sets - pair and returns if does not exist in the cache. -// The key-value pair expires after milliseconds. -// If <=0 means it does not expire. +// The key-value pair expires after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func (c *memCache) GetOrSet(key interface{}, value interface{}, duration interface{}) interface{} { if v := c.Get(key); v == nil { return c.doSetWithLockCheck(key, value, duration) @@ -216,8 +231,11 @@ func (c *memCache) GetOrSet(key interface{}, value interface{}, duration interfa // GetOrSetFunc returns the value of , // or sets with result of function and returns its result // if does not exist in the cache. -// The key-value pair expires after milliseconds. -// If <=0 means it does not expire. +// The key-value pair expires after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. func (c *memCache) GetOrSetFunc(key interface{}, f func() interface{}, duration interface{}) interface{} { if v := c.Get(key); v == nil { return c.doSetWithLockCheck(key, f(), duration) @@ -229,8 +247,11 @@ func (c *memCache) GetOrSetFunc(key interface{}, f func() interface{}, duration // GetOrSetFuncLock returns the value of , // or sets with result of function and returns its result // if does not exist in the cache. -// The key-value pair expires after milliseconds. -// If <=0 means it does not expire. +// The key-value pair expires after . +// +// The parameter can be either type of int or time.Duration. +// If is type of int, it means milliseconds. +// If <=0 means it does not expire. // // Note that the function is executed within writing mutex lock. func (c *memCache) GetOrSetFuncLock(key interface{}, f func() interface{}, duration interface{}) interface{} {