Documentation ¶
Index ¶
- func GetCache() mc.Cache
- func GetContextData(ctx context.Context, tp, key any) any
- func GetInt(key string, getFunc func() (int, error)) (int, error)
- func GetInt64(key string, getFunc func() (int64, error)) (int64, error)
- func GetString(key string, getFunc func() (string, error)) (string, error)
- func GetWithContextCache[T any](ctx context.Context, cacheGroupKey string, cacheTargetID any, ...) (T, error)
- func NewContext() error
- func Remove(key string)
- func RemoveContextData(ctx context.Context, tp, key any)
- func SetContextData(ctx context.Context, tp, key, value any)
- func WithCacheContext(ctx context.Context) context.Context
- func WithNoCacheContext(ctx context.Context) context.Context
- type MemoryItem
- type RedisCacher
- func (c *RedisCacher) Decr(key string) error
- func (c *RedisCacher) Delete(key string) error
- func (c *RedisCacher) Flush() error
- func (c *RedisCacher) Get(key string) interface{}
- func (c *RedisCacher) Incr(key string) error
- func (c *RedisCacher) IsExist(key string) bool
- func (c *RedisCacher) Ping() error
- func (c *RedisCacher) Put(key string, val interface{}, expire int64) error
- func (c *RedisCacher) StartAndGC(opts cache.Options) error
- type TwoQueueCache
- func (c *TwoQueueCache) Decr(key string) error
- func (c *TwoQueueCache) Delete(key string) error
- func (c *TwoQueueCache) Flush() error
- func (c *TwoQueueCache) Get(key string) interface{}
- func (c *TwoQueueCache) Incr(key string) error
- func (c *TwoQueueCache) IsExist(key string) bool
- func (c *TwoQueueCache) Ping() error
- func (c *TwoQueueCache) Put(key string, val interface{}, timeout int64) error
- func (c *TwoQueueCache) StartAndGC(opts mc.Options) error
- type TwoQueueCacheConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetString ¶ added in v1.12.0
GetString returns the key value from cache with callback when no key exists in cache
func GetWithContextCache ¶ added in v1.19.0
func GetWithContextCache[T any](ctx context.Context, cacheGroupKey string, cacheTargetID any, f func() (T, error)) (T, error)
GetWithContextCache returns the cache value of the given key in the given context.
func RemoveContextData ¶ added in v1.19.0
func SetContextData ¶ added in v1.19.0
Types ¶
type MemoryItem ¶ added in v1.15.0
MemoryItem represents a memory cache item.
type RedisCacher ¶ added in v1.13.0
type RedisCacher struct {
// contains filtered or unexported fields
}
RedisCacher represents a redis cache adapter implementation.
func (*RedisCacher) Decr ¶ added in v1.13.0
func (c *RedisCacher) Decr(key string) error
Decr decreases cached int-type value by given key as a counter.
func (*RedisCacher) Delete ¶ added in v1.13.0
func (c *RedisCacher) Delete(key string) error
Delete deletes cached value by given key.
func (*RedisCacher) Flush ¶ added in v1.13.0
func (c *RedisCacher) Flush() error
Flush deletes all cached data.
func (*RedisCacher) Get ¶ added in v1.13.0
func (c *RedisCacher) Get(key string) interface{}
Get gets cached value by given key.
func (*RedisCacher) Incr ¶ added in v1.13.0
func (c *RedisCacher) Incr(key string) error
Incr increases cached int-type value by given key as a counter.
func (*RedisCacher) IsExist ¶ added in v1.13.0
func (c *RedisCacher) IsExist(key string) bool
IsExist returns true if cached value exists.
func (*RedisCacher) Ping ¶ added in v1.17.0
func (c *RedisCacher) Ping() error
Ping tests if the cache is alive.
func (*RedisCacher) Put ¶ added in v1.13.0
func (c *RedisCacher) Put(key string, val interface{}, expire int64) error
Put puts value (string type) into cache with key and expire time. If expired is 0, it lives forever.
func (*RedisCacher) StartAndGC ¶ added in v1.13.0
func (c *RedisCacher) StartAndGC(opts cache.Options) error
StartAndGC starts GC routine based on config string settings. AdapterConfig: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180,hset_name=MacaronCache,prefix=cache:
type TwoQueueCache ¶ added in v1.15.0
type TwoQueueCache struct {
// contains filtered or unexported fields
}
TwoQueueCache represents a LRU 2Q cache adapter implementation
func (*TwoQueueCache) Decr ¶ added in v1.15.0
func (c *TwoQueueCache) Decr(key string) error
Decr decreases cached int-type value by given key as a counter.
func (*TwoQueueCache) Delete ¶ added in v1.15.0
func (c *TwoQueueCache) Delete(key string) error
Delete deletes cached value by given key.
func (*TwoQueueCache) Flush ¶ added in v1.15.0
func (c *TwoQueueCache) Flush() error
Flush deletes all cached data.
func (*TwoQueueCache) Get ¶ added in v1.15.0
func (c *TwoQueueCache) Get(key string) interface{}
Get gets cached value by given key.
func (*TwoQueueCache) Incr ¶ added in v1.15.0
func (c *TwoQueueCache) Incr(key string) error
Incr increases cached int-type value by given key as a counter.
func (*TwoQueueCache) IsExist ¶ added in v1.15.0
func (c *TwoQueueCache) IsExist(key string) bool
IsExist returns true if cached value exists.
func (*TwoQueueCache) Ping ¶ added in v1.17.0
func (c *TwoQueueCache) Ping() error
Ping tests if the cache is alive.
func (*TwoQueueCache) Put ¶ added in v1.15.0
func (c *TwoQueueCache) Put(key string, val interface{}, timeout int64) error
Put puts value into cache with key and expire time.
func (*TwoQueueCache) StartAndGC ¶ added in v1.15.0
func (c *TwoQueueCache) StartAndGC(opts mc.Options) error
StartAndGC starts GC routine based on config string settings.
type TwoQueueCacheConfig ¶ added in v1.15.0
type TwoQueueCacheConfig struct { Size int `ini:"SIZE" json:"size"` RecentRatio float64 `ini:"RECENT_RATIO" json:"recent_ratio"` GhostRatio float64 `ini:"GHOST_RATIO" json:"ghost_ratio"` }
TwoQueueCacheConfig describes the configuration for TwoQueueCache