Documentation ¶
Index ¶
- func Contains(key interface{}) bool
- func Data() map[interface{}]interface{}
- func Get(key interface{}) interface{}
- func GetOrSet(key interface{}, value interface{}, duration interface{}) interface{}
- func GetOrSetFunc(key interface{}, f func() interface{}, duration interface{}) interface{}
- func GetOrSetFuncLock(key interface{}, f func() interface{}, duration interface{}) interface{}
- func KeyStrings() []string
- func Keys() []interface{}
- func Remove(key interface{}) interface{}
- func Removes(keys []interface{})
- func Set(key interface{}, value interface{}, duration interface{})
- func SetIfNotExist(key interface{}, value interface{}, duration interface{}) bool
- func Sets(data map[interface{}]interface{}, duration interface{})
- func Size() int
- func Values() []interface{}
- type TCache
- func (c *TCache) Clear()
- func (c TCache) Close()
- func (c TCache) Contains(key interface{}) bool
- func (c TCache) Data() map[interface{}]interface{}
- func (c TCache) Get(key interface{}) interface{}
- func (c TCache) GetOrSet(key interface{}, value interface{}, duration interface{}) interface{}
- func (c TCache) GetOrSetFunc(key interface{}, f func() interface{}, duration interface{}) interface{}
- func (c TCache) GetOrSetFuncLock(key interface{}, f func() interface{}, duration interface{}) interface{}
- func (c TCache) KeyStrings() []string
- func (c TCache) Keys() []interface{}
- func (c TCache) Remove(key interface{}) (value interface{})
- func (c TCache) Removes(keys []interface{})
- func (c TCache) Set(key interface{}, value interface{}, duration interface{})
- func (c TCache) SetIfNotExist(key interface{}, value interface{}, duration interface{}) bool
- func (c TCache) Sets(data map[interface{}]interface{}, duration interface{})
- func (c TCache) Size() (size int)
- func (c TCache) Values() []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOrSetFunc ¶
func GetOrSetFunc(key interface{}, f func() interface{}, duration interface{}) interface{}
func GetOrSetFuncLock ¶
func GetOrSetFuncLock(key interface{}, f func() interface{}, duration interface{}) interface{}
func KeyStrings ¶
func KeyStrings() []string
func SetIfNotExist ¶
func SetIfNotExist(key interface{}, value interface{}, duration interface{}) bool
Types ¶
type TCache ¶
type TCache struct {
// contains filtered or unexported fields
}
func (TCache) Contains ¶
func (c TCache) Contains(key interface{}) bool
Contains returns true if <key> exists in the cache, or else returns false.
func (TCache) Data ¶
func (c TCache) Data() map[interface{}]interface{}
Data returns a copy of all key-value pairs in the cache as map type.
func (TCache) Get ¶
func (c TCache) Get(key interface{}) interface{}
Get returns the value of <key>. It returns nil if it does not exist or its value is nil.
func (TCache) GetOrSet ¶
func (c TCache) GetOrSet(key interface{}, value interface{}, duration interface{}) interface{}
GetOrSet returns the value of <key>, or sets <key>-<value> pair and returns <value> if <key> does not exist in the cache. The key-value pair expires after <duration>.
The parameter <duration> can be either type of int or time.Duration. If <duration> is type of int, it means <duration> milliseconds. If <duration> <=0 means it does not expire.
func (TCache) GetOrSetFunc ¶
func (c TCache) GetOrSetFunc(key interface{}, f func() interface{}, duration interface{}) interface{}
GetOrSetFunc returns the value of <key>, or sets <key> with result of function <f> and returns its result if <key> does not exist in the cache. The key-value pair expires after <duration>.
The parameter <duration> can be either type of int or time.Duration. If <duration> is type of int, it means <duration> milliseconds. If <duration> <=0 means it does not expire.
func (TCache) GetOrSetFuncLock ¶
func (c TCache) GetOrSetFuncLock(key interface{}, f func() interface{}, duration interface{}) interface{}
GetOrSetFuncLock returns the value of <key>, or sets <key> with result of function <f> and returns its result if <key> does not exist in the cache. The key-value pair expires after <duration>.
The parameter <duration> can be either type of int or time.Duration. If <duration> is type of int, it means <duration> milliseconds. If <duration> <=0 means it does not expire.
Note that the function <f> is executed within writing mutex lock.
func (TCache) KeyStrings ¶
func (c TCache) KeyStrings() []string
KeyStrings returns all keys in the cache as string slice.
func (TCache) Keys ¶
func (c TCache) Keys() []interface{}
Keys returns all keys in the cache as slice.
func (TCache) Remove ¶
func (c TCache) Remove(key interface{}) (value interface{})
Remove deletes the <key> in the cache, and returns its value.
func (TCache) Removes ¶
func (c TCache) Removes(keys []interface{})
Removes deletes <keys> in the cache.
func (TCache) Set ¶
func (c TCache) Set(key interface{}, value interface{}, duration interface{})
Set sets cache with <key>-<value> pair, which is expired after <duration>.
The parameter <duration> can be either type of int or time.Duration. If <duration> is type of int, it means <duration> milliseconds. If <duration> <=0 means it does not expire.
func (TCache) SetIfNotExist ¶
func (c TCache) SetIfNotExist(key interface{}, value interface{}, duration interface{}) bool
SetIfNotExist sets cache with <key>-<value> pair if <key> does not exist in the cache, which is expired after <duration>.
The parameter <duration> can be either type of int or time.Duration. If <duration> is type of int, it means <duration> milliseconds. If <duration> <=0 means it does not expire.
func (TCache) Sets ¶
func (c TCache) Sets(data map[interface{}]interface{}, duration interface{})
Sets batch sets cache with key-value pairs by <data>, which is expired after <duration>.
The parameter <duration> can be either type of int or time.Duration. If <duration> is type of int, it means <duration> milliseconds. If <duration> <=0 means it does not expire.