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, ...) interface{}
- func (c *GfCache) GetOrSetFunc(ctx context.Context, key string, f gcache.Func, duration time.Duration, ...) interface{}
- func (c *GfCache) GetOrSetFuncLock(ctx context.Context, key string, f gcache.Func, duration time.Duration, ...) interface{}
- 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) interface{}
- 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 ¶
type GfCache struct { CachePrefix string //缓存前缀 // contains filtered or unexported fields }
func (*GfCache) Contains ¶
Contains returns true if <tagKey> exists in the cache, or else returns false.
func (*GfCache) Get ¶
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 ¶
KeyStrings returns all keys in the cache as string slice.
func (*GfCache) RemoveByTag ¶
RemoveByTag deletes the <tag> in the cache, and returns its value.
func (*GfCache) RemoveByTags ¶
RemoveByTags deletes <tags> 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.
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 }