Documentation ¶
Overview ¶
Package gcache provides high performance and concurrent-safe in-memory cache for process.
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 Cache
- func (c *Cache) Clear()
- func (c Cache) Close()
- func (c Cache) Contains(key interface{}) bool
- func (c Cache) Data() map[interface{}]interface{}
- func (c Cache) Get(key interface{}) interface{}
- func (c Cache) GetOrSet(key interface{}, value interface{}, duration interface{}) interface{}
- func (c Cache) GetOrSetFunc(key interface{}, f func() interface{}, duration interface{}) interface{}
- func (c Cache) GetOrSetFuncLock(key interface{}, f func() interface{}, duration interface{}) interface{}
- func (c Cache) KeyStrings() []string
- func (c Cache) Keys() []interface{}
- func (c Cache) Remove(key interface{}) (value interface{})
- func (c Cache) Removes(keys []interface{})
- func (c Cache) Set(key interface{}, value interface{}, duration interface{})
- func (c Cache) SetIfNotExist(key interface{}, value interface{}, duration interface{}) bool
- func (c Cache) Sets(data map[interface{}]interface{}, duration interface{})
- func (c Cache) Size() (size int)
- func (c Cache) Values() []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains(key interface{}) bool
Contains returns true if <key> exists in the cache, or else returns false.
func Data ¶
func Data() map[interface{}]interface{}
Data returns a copy of all key-value pairs in the cache as map type.
func Get ¶
func Get(key interface{}) interface{}
Get returns the value of <key>. It returns nil if it does not exist or its value is nil.
func GetOrSet ¶
func 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 GetOrSetFunc ¶
func 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 GetOrSetFuncLock ¶
func 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 KeyStrings ¶
func KeyStrings() []string
KeyStrings returns all keys in the cache as string slice.
func Remove ¶
func Remove(key interface{}) interface{}
Remove deletes the <key> in the cache, and returns its value.
func Set ¶
func 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 SetIfNotExist ¶
func 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 Sets ¶
func 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.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache struct.
func (Cache) Contains ¶
func (c Cache) Contains(key interface{}) bool
Contains returns true if <key> exists in the cache, or else returns false.
func (Cache) Data ¶
func (c Cache) Data() map[interface{}]interface{}
Data returns a copy of all key-value pairs in the cache as map type.
func (Cache) Get ¶
func (c Cache) Get(key interface{}) interface{}
Get returns the value of <key>. It returns nil if it does not exist or its value is nil.
func (Cache) GetOrSet ¶
func (c Cache) 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 (Cache) GetOrSetFunc ¶
func (c Cache) 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 (Cache) GetOrSetFuncLock ¶
func (c Cache) 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 (Cache) KeyStrings ¶
func (c Cache) KeyStrings() []string
KeyStrings returns all keys in the cache as string slice.
func (Cache) Keys ¶
func (c Cache) Keys() []interface{}
Keys returns all keys in the cache as slice.
func (Cache) Remove ¶
func (c Cache) Remove(key interface{}) (value interface{})
Remove deletes the <key> in the cache, and returns its value.
func (Cache) Removes ¶
func (c Cache) Removes(keys []interface{})
Removes deletes <keys> in the cache.
func (Cache) Set ¶
func (c Cache) 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 (Cache) SetIfNotExist ¶
func (c Cache) 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 (Cache) Sets ¶
func (c Cache) 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.