Documentation ¶
Index ¶
- type GfCache
- func (c *GfCache) Contains(ctx context.Context, key string) bool
- func (c *GfCache) Data(ctx context.Context) map[interface{}]interface{}
- func (c *GfCache) Get(ctx context.Context, key string) *gvar.Var
- func (c *GfCache) GetOrSet(ctx context.Context, key string, value interface{}, duration time.Duration, ...) *gvar.Var
- func (c *GfCache) GetOrSetFunc(ctx context.Context, key string, f gcache.Func, duration time.Duration, ...) *gvar.Var
- func (c *GfCache) GetOrSetFuncLock(ctx context.Context, key string, f gcache.Func, duration time.Duration, ...) *gvar.Var
- func (c *GfCache) KeyStrings(ctx context.Context) []string
- func (c *GfCache) Keys(ctx context.Context) []interface{}
- func (c *GfCache) Remove(ctx context.Context, key string) *gvar.Var
- func (c *GfCache) RemoveByTag(ctx context.Context, tag string)
- func (c *GfCache) RemoveByTags(ctx context.Context, tag []string)
- func (c *GfCache) Removes(ctx context.Context, keys []string)
- func (c *GfCache) Set(ctx context.Context, key string, value interface{}, duration time.Duration, ...)
- func (c *GfCache) SetIfNotExist(ctx context.Context, key string, value interface{}, duration time.Duration, ...) bool
- func (c *GfCache) Size(ctx context.Context) int
- func (c *GfCache) Values(ctx context.Context) []interface{}
- type IGCache
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 (*GfCache) Contains ¶ added in v0.0.3
Contains returns true if <tagKey> exists in the cache, or else returns false.
func (*GfCache) Data ¶ added in v0.0.3
Data returns a copy of all tagKey-value pairs in the cache as map type.
func (*GfCache) Get ¶ added in v0.0.3
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
KeyStrings returns all keys in the cache as string slice.
func (*GfCache) Remove ¶ added in v0.0.3
Remove deletes the <tagKey> in the cache, and returns its value.
func (*GfCache) RemoveByTag ¶ added in v0.0.3
RemoveByTag deletes the <tag> in the cache, and returns its value.
func (*GfCache) RemoveByTags ¶ added in v0.0.3
RemoveByTags deletes <tags> 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.
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 }