Documentation ¶
Index ¶
- Variables
- func WrapErrKeyExpired(key string) error
- func WrapErrKeyNotFound(key string) error
- func WrapErrOverCapacity() error
- type BuildInCache
- func (b *BuildInCache) Close() error
- func (b *BuildInCache) Delete(ctx context.Context, key string) error
- func (b *BuildInCache) Get(ctx context.Context, key string) (any, error)
- func (b *BuildInCache) LoadAndDelete(ctx context.Context, key string) (any, error)
- func (b *BuildInCache) Set(ctx context.Context, key string, val any, expiration time.Duration) error
- type BuildInCacheOption
- type Cache
- type MaxCntCache
- type RandomExpirationCache
- type RedisCache
- func (r *RedisCache) Delete(ctx context.Context, key string) error
- func (r *RedisCache) Get(ctx context.Context, key string) (any, error)
- func (r *RedisCache) LoadAndDelete(ctx context.Context, key string) (any, error)
- func (r *RedisCache) Set(ctx context.Context, key string, val any, expiration time.Duration) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrKeyNotFound = errors.New("cache:键不存在") ErrKeyExpired = errors.New("cache:键过期") )
Functions ¶
func WrapErrKeyExpired ¶
func WrapErrKeyNotFound ¶
func WrapErrOverCapacity ¶
func WrapErrOverCapacity() error
Types ¶
type BuildInCache ¶
type BuildInCache struct {
// contains filtered or unexported fields
}
BuildInCache 基于内存的本地缓存 1. 并发安全 2. 过期删除机制:(1)延时删除,即Get()数据时,发现数据过期,则删除 (2)轮询定时删除一定数量的数据
func NewBuildInCache ¶
func NewBuildInCache(interval time.Duration, opts ...BuildInCacheOption) *BuildInCache
func (*BuildInCache) Close ¶
func (b *BuildInCache) Close() error
func (*BuildInCache) LoadAndDelete ¶
type BuildInCacheOption ¶
type BuildInCacheOption func(cache *BuildInCache)
type MaxCntCache ¶
type MaxCntCache struct { *BuildInCache // contains filtered or unexported fields }
func NewMaxCntCache ¶
func NewMaxCntCache(c *BuildInCache, maxCnt int64) *MaxCntCache
type RandomExpirationCache ¶
type RandomExpirationCache struct {
Cache
}
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
func NewRedisCache ¶
func NewRedisCache(c redis.Cmdable) *RedisCache
func (*RedisCache) LoadAndDelete ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.