Documentation
¶
Index ¶
- type CacheManager
- func (cm *CacheManager) Delete(ctx context.Context, keys ...string) error
- func (cm *CacheManager) Get(ctx context.Context, key string, loader func() (interface{}, error), ...) error
- func (cm *CacheManager) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- func (cm *CacheManager) SetEmptyCache(ctx context.Context, key string, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheManager ¶
type CacheManager struct {
// contains filtered or unexported fields
}
func NewLocalCacheManager ¶
func NewLocalCacheManager(redisClient redis.Cmdable) *CacheManager
func (*CacheManager) Delete ¶
func (cm *CacheManager) Delete(ctx context.Context, keys ...string) error
Delete 从本地缓存和 Redis 中删除一个或多个键
func (*CacheManager) Get ¶
func (cm *CacheManager) Get(ctx context.Context, key string, loader func() (interface{}, error), result interface{}) error
Get 从缓存中获取数据,如果缓存未命中,则调用 loader 加载数据并缓存
func (*CacheManager) Set ¶
func (cm *CacheManager) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
Set 缓存数据到本地缓存和 Redis
func (*CacheManager) SetEmptyCache ¶
SetEmptyCache 缓存空对象,防止缓存穿透
Click to show internal directories.
Click to hide internal directories.