gf: github.com/gogf/gf/g/os/gcache Index | Files

package gcache

import "github.com/gogf/gf/g/os/gcache"

Package gcache provides high performance and concurrent-safe in-memory cache for process.

Index

Package Files

gcache.go gcache_cache.go gcache_mem_cache.go gcache_mem_cache_item.go gcache_mem_cache_lru.go

func Contains Uses

func Contains(key interface{}) bool

Contains returns true if <key> exists in the cache, or else returns false.

func Data Uses

func Data() map[interface{}]interface{}

Data returns a copy of all key-value pairs in the cache as map type.

func Get Uses

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 Uses

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 <expire> milliseconds. If <expire> <=0 means it does not expire.

func GetOrSetFunc Uses

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 <expire> milliseconds. If <expire> <=0 means it does not expire.

func GetOrSetFuncLock Uses

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 <expire> milliseconds. If <expire> <=0 means it does not expire.

Note that the function <f> is executed within writing mutex lock.

func KeyStrings Uses

func KeyStrings() []string

KeyStrings returns all keys in the cache as string slice.

func Keys Uses

func Keys() []interface{}

Keys returns all keys in the cache as slice.

func Remove Uses

func Remove(key interface{}) interface{}

Remove deletes the <key> in the cache, and returns its value.

func Removes Uses

func Removes(keys []interface{})

Removes deletes <keys> in the cache.

func Set Uses

func Set(key interface{}, value interface{}, duration interface{})

Set sets cache with <key>-<value> pair, which is expired after <expire> milliseconds. If <expire> <=0 means it does not expire.

func SetIfNotExist Uses

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 <expire> milliseconds. If <expire> <=0 means it does not expire.

func Sets Uses

func Sets(data map[interface{}]interface{}, duration interface{})

Sets batch sets cache with key-value pairs by <data>, which is expired after <expire> milliseconds. If <expire> <=0 means it does not expire.

func Size Uses

func Size() int

Size returns the size of the cache.

func Values Uses

func Values() []interface{}

Values returns all values in the cache as slice.

type Cache Uses

type Cache struct {
    // contains filtered or unexported fields
}

Cache struct.

func New Uses

func New(lruCap ...int) *Cache

New creates and returns a new cache object.

func (*Cache) Clear Uses

func (c *Cache) Clear()

Clear clears all data of the cache.

func (Cache) Close Uses

func (c Cache) Close()

Close closes the cache.

func (Cache) Contains Uses

func (c Cache) Contains(key interface{}) bool

Contains returns true if <key> exists in the cache, or else returns false.

func (Cache) Data Uses

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 Uses

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 Uses

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 <expire> milliseconds. If <expire> <=0 means it does not expire.

func (Cache) GetOrSetFunc Uses

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 <expire> milliseconds. If <expire> <=0 means it does not expire.

func (Cache) GetOrSetFuncLock Uses

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 <expire> milliseconds. If <expire> <=0 means it does not expire.

Note that the function <f> is executed within writing mutex lock.

func (Cache) KeyStrings Uses

func (c Cache) KeyStrings() []string

KeyStrings returns all keys in the cache as string slice.

func (Cache) Keys Uses

func (c Cache) Keys() []interface{}

Keys returns all keys in the cache as slice.

func (Cache) Remove Uses

func (c Cache) Remove(key interface{}) (value interface{})

Remove deletes the <key> in the cache, and returns its value.

func (Cache) Removes Uses

func (c Cache) Removes(keys []interface{})

Removes deletes <keys> in the cache.

func (Cache) Set Uses

func (c Cache) Set(key interface{}, value interface{}, duration interface{})

Set sets cache with <key>-<value> pair, which is expired after <expire> milliseconds. If <expire> <=0 means it does not expire.

func (Cache) SetIfNotExist Uses

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 <expire> milliseconds. If <expire> <=0 means it does not expire.

func (Cache) Sets Uses

func (c Cache) Sets(data map[interface{}]interface{}, duration interface{})

Sets batch sets cache with key-value pairs by <data>, which is expired after <expire> milliseconds. If <expire> <=0 means it does not expire.

func (Cache) Size Uses

func (c Cache) Size() (size int)

Size returns the size of the cache.

func (Cache) Values Uses

func (c Cache) Values() []interface{}

Values returns all values in the cache as slice.

Package gcache imports 12 packages (graph) and is imported by 12 packages. Updated 2019-07-15. Refresh now. Tools for package owners.