Documentation
¶
Overview ¶
Package cache is memory and redis cache libraries.
Index ¶
- Variables
- func BuildCacheKey(keyPrefix string, key string) (string, error)
- func CloseGlobalMemory() error
- func Del(ctx context.Context, keys ...string) error
- func Get(ctx context.Context, key string, val interface{}) error
- func GetGlobalMemoryCli() *ristretto.Cache
- func InitGlobalMemory(opts ...Option)
- func InitMemory(opts ...Option) *ristretto.Cache
- func MultiGet(ctx context.Context, keys []string, valueMap interface{}) error
- func MultiSet(ctx context.Context, valMap map[string]interface{}, expiration time.Duration) error
- func Set(ctx context.Context, key string, val interface{}, expiration time.Duration) error
- func SetCacheWithNotFound(ctx context.Context, key string) error
- type Cache
- func NewMemoryCache(keyPrefix string, encode encoding.Encoding, newObject func() interface{}) Cache
- func NewRedisCache(client *redis.Client, keyPrefix string, encode encoding.Encoding, ...) Cache
- func NewRedisClusterCache(client *redis.ClusterClient, keyPrefix string, encode encoding.Encoding, ...) Cache
- type Option
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultExpireTime default expiry time DefaultExpireTime = time.Hour * 24 // DefaultNotFoundExpireTime expiry time when result is empty 1 minute, // often used for cache time when data is empty (cache pass-through) DefaultNotFoundExpireTime = time.Minute * 10 // NotFoundPlaceholder placeholder NotFoundPlaceholder = "*" NotFoundPlaceholderBytes = []byte(NotFoundPlaceholder) ErrPlaceholder = errors.New("cache: placeholder") // DefaultClient generate a cache client, where keyPrefix is generally the business prefix DefaultClient Cache )
View Source
var CacheNotFound = redis.Nil
CacheNotFound no hit cache
Functions ¶
func BuildCacheKey ¶
BuildCacheKey construct a cache key with a prefix
func CloseGlobalMemory ¶ added in v1.12.8
func CloseGlobalMemory() error
CloseGlobalMemory close memory cache
func GetGlobalMemoryCli ¶ added in v1.12.8
GetGlobalMemoryCli get memory cache client
func InitGlobalMemory ¶ added in v1.12.8
func InitGlobalMemory(opts ...Option)
InitGlobalMemory init global memory cache
func InitMemory ¶ added in v1.12.8
InitMemory create a memory cache
Types ¶
type Cache ¶
type Cache interface { Set(ctx context.Context, key string, val interface{}, expiration time.Duration) error Get(ctx context.Context, key string, val interface{}) error MultiSet(ctx context.Context, valMap map[string]interface{}, expiration time.Duration) error MultiGet(ctx context.Context, keys []string, valueMap interface{}) error Del(ctx context.Context, keys ...string) error SetCacheWithNotFound(ctx context.Context, key string) error }
Cache driver interface
func NewMemoryCache ¶
NewMemoryCache create a memory cache
type Option ¶ added in v1.12.8
type Option func(*options)
Option set the jwt options.
func WithBufferItems ¶ added in v1.12.8
WithBufferItems set number of keys per Get buffer.
func WithMaxCost ¶ added in v1.12.8
WithMaxCost set maximum cost of cache.
func WithNumCounters ¶ added in v1.12.8
WithNumCounters set number of keys.
Click to show internal directories.
Click to hide internal directories.