cache

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GfCache added in v0.0.3

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

func New added in v0.0.2

func New(cachePrefix string) *GfCache

New 使用内存缓存

func NewDist added in v1.0.4

func NewDist(cachePrefix ...string) *GfCache

func NewRedis

func NewRedis(cachePrefix string, redisName ...string) *GfCache

NewRedis 使用redis缓存

func (*GfCache) Contains added in v0.0.3

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 added in v0.0.3

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 added in v0.0.3

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 added in v0.0.3

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

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 added in v0.0.3

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

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 added in v0.0.3

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

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 added in v0.0.3

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

KeyStrings returns all keys in the cache as string slice.

func (*GfCache) Keys added in v0.0.3

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

Keys returns all keys in the cache as slice.

func (*GfCache) Remove added in v0.0.3

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

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

func (*GfCache) RemoveByTag added in v0.0.3

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

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

func (*GfCache) RemoveByTags added in v0.0.3

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

RemoveByTags deletes <tags> in the cache.

func (*GfCache) Removes added in v0.0.3

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

Removes deletes <keys> in the cache.

func (*GfCache) Set added in v0.0.3

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 added in v0.0.3

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 added in v0.0.3

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

Size returns the size of the cache.

func (*GfCache) Values added in v0.0.3

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

Values returns all values in the cache as slice.

type IGCache added in v0.0.3

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) *gvar.Var
	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) *gvar.Var
	GetOrSetFunc(ctx context.Context, key string, f gcache.Func, duration time.Duration, tag string) *gvar.Var
	GetOrSetFuncLock(ctx context.Context, key string, f gcache.Func, duration time.Duration, tag string) *gvar.Var
	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