xcache

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(key interface{}) bool

func Data

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

func Get

func Get(key interface{}) interface{}

func GetOrSet

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

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 Keys

func Keys() []interface{}

func Remove

func Remove(key interface{}) interface{}

func Removes

func Removes(keys []interface{})

func Set

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

func SetIfNotExist

func SetIfNotExist(key interface{}, value interface{}, duration interface{}) bool

func Sets

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

func Size

func Size() int

func Values

func Values() []interface{}

Types

type TCache

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

func New

func New(lruCap ...int) *TCache

func (*TCache) Clear

func (c *TCache) Clear()

func (TCache) Close

func (c TCache) Close()

Close closes the cache.

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.

func (TCache) Size

func (c TCache) Size() (size int)

Size returns the size of the cache.

func (TCache) Values

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

Values returns all values in the cache as slice.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL