libCache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GfCache

type GfCache struct {
	CachePrefix string //缓存前缀
	// contains filtered or unexported fields
}

func New

func New(cachePrefix string) *GfCache

New 使用内存缓存

func NewRedis

func NewRedis(cachePrefix string) *GfCache

NewRedis 使用redis缓存

func (*GfCache) Contains

func (c *GfCache) Contains(ctx context.Context, key string) bool

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

func (*GfCache) Data

func (c *GfCache) Data(ctx context.Context) map[interface{}]interface{}

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

func (*GfCache) Get

func (c *GfCache) Get(ctx context.Context, key string) *gvar.Var

Get returns the value of <tagKey>. It returns nil if it does not exist or its value is nil.

func (*GfCache) GetOrSet

func (c *GfCache) GetOrSet(ctx context.Context, key string, value interface{}, duration time.Duration, tag string) interface{}

GetOrSet returns the value of <tagKey>, or sets <tagKey>-<value> pair and returns <value> if <tagKey> does not exist in the cache. The tagKey-value pair expires after <duration>.

It does not expire if <duration> <= 0.

func (*GfCache) GetOrSetFunc

func (c *GfCache) GetOrSetFunc(ctx context.Context, key string, f gcache.Func, duration time.Duration, tag string) interface{}

GetOrSetFunc returns the value of <tagKey>, or sets <tagKey> with result of function <f> and returns its result if <tagKey> does not exist in the cache. The tagKey-value pair expires after <duration>. It does not expire if <duration> <= 0.

func (*GfCache) GetOrSetFuncLock

func (c *GfCache) GetOrSetFuncLock(ctx context.Context, key string, f gcache.Func, duration time.Duration, tag string) interface{}

GetOrSetFuncLock returns the value of <tagKey>, or sets <tagKey> with result of function <f> and returns its result if <tagKey> does not exist in the cache. The tagKey-value pair expires after <duration>. It does not expire if <duration> <= 0.

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

func (*GfCache) KeyStrings

func (c *GfCache) KeyStrings(ctx context.Context) []string

KeyStrings returns all keys in the cache as string slice.

func (*GfCache) Keys

func (c *GfCache) Keys(ctx context.Context) []interface{}

Keys returns all keys in the cache as slice.

func (*GfCache) Remove

func (c *GfCache) Remove(ctx context.Context, key string) interface{}

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

func (*GfCache) RemoveByTag

func (c *GfCache) RemoveByTag(ctx context.Context, tag string)

RemoveByTag deletes the <tag> in the cache, and returns its value.

func (*GfCache) RemoveByTags

func (c *GfCache) RemoveByTags(ctx context.Context, tag []string)

RemoveByTags deletes <tags> in the cache.

func (*GfCache) Removes

func (c *GfCache) Removes(ctx context.Context, keys []string)

Removes deletes <keys> in the cache.

func (*GfCache) Set

func (c *GfCache) Set(ctx context.Context, key string, value interface{}, duration time.Duration, tag ...string)

Set sets cache with <tagKey>-<value> pair, which is expired after <duration>. It does not expire if <duration> <= 0.

func (*GfCache) SetIfNotExist

func (c *GfCache) SetIfNotExist(ctx context.Context, key string, value interface{}, duration time.Duration, tag string) bool

SetIfNotExist sets cache with <tagKey>-<value> pair if <tagKey> does not exist in the cache, which is expired after <duration>. It does not expire if <duration> <= 0.

func (*GfCache) Size

func (c *GfCache) Size(ctx context.Context) int

Size returns the size of the cache.

func (*GfCache) Values

func (c *GfCache) Values(ctx context.Context) []interface{}

Values returns all values in the cache as slice.

type IGCache

type IGCache interface {
	Get(ctx context.Context, key string) *gvar.Var
	Set(ctx context.Context, key string, value interface{}, duration time.Duration, tag ...string)
	Remove(ctx context.Context, key string) interface{}
	Removes(ctx context.Context, keys []string)
	RemoveByTag(ctx context.Context, tag string)
	RemoveByTags(ctx context.Context, tag []string)
	SetIfNotExist(ctx context.Context, key string, value interface{}, duration time.Duration, tag string) bool
	GetOrSet(ctx context.Context, key string, value interface{}, duration time.Duration, tag string) interface{}
	GetOrSetFunc(ctx context.Context, key string, f gcache.Func, duration time.Duration, tag string) interface{}
	GetOrSetFuncLock(ctx context.Context, key string, f gcache.Func, duration time.Duration, tag string) interface{}
	Contains(ctx context.Context, key string) bool
	Data(ctx context.Context) map[interface{}]interface{}
	Keys(ctx context.Context) []interface{}
	KeyStrings(ctx context.Context) []string
	Values(ctx context.Context) []interface{}
	Size(ctx context.Context) int
}

Jump to

Keyboard shortcuts

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