cache

package
v0.0.0-...-e20221d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("cache:键不存在")
	ErrKeyExpired  = errors.New("cache:键过期")
)

Functions

func WrapErrKeyExpired

func WrapErrKeyExpired(key string) error

func WrapErrKeyNotFound

func WrapErrKeyNotFound(key string) error

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) Delete

func (b *BuildInCache) Delete(ctx context.Context, key string) error

func (*BuildInCache) Get

func (b *BuildInCache) Get(ctx context.Context, key string) (any, error)

func (*BuildInCache) LoadAndDelete

func (b *BuildInCache) LoadAndDelete(ctx context.Context, key string) (any, error)

func (*BuildInCache) Set

func (b *BuildInCache) Set(ctx context.Context, key string, val any, expiration time.Duration) error

type BuildInCacheOption

type BuildInCacheOption func(cache *BuildInCache)

type Cache

type Cache interface {
	Set(ctx context.Context, key string, val any, expiration time.Duration) error
	Get(ctx context.Context, key string) (any, error)
	Delete(ctx context.Context, key string) error
	LoadAndDelete(ctx context.Context, key string) (any, error)
}

type MaxCntCache

type MaxCntCache struct {
	*BuildInCache
	// contains filtered or unexported fields
}

func NewMaxCntCache

func NewMaxCntCache(c *BuildInCache, maxCnt int64) *MaxCntCache

func (*MaxCntCache) Set

func (m *MaxCntCache) Set(ctx context.Context, key string, val any, expiration time.Duration) error

type RandomExpirationCache

type RandomExpirationCache struct {
	Cache
}

func (*RandomExpirationCache) Set

func (r *RandomExpirationCache) Set(ctx context.Context, key string, val any, expiration time.Duration) error

type RedisCache

type RedisCache struct {
	// contains filtered or unexported fields
}

func NewRedisCache

func NewRedisCache(c redis.Cmdable) *RedisCache

func (*RedisCache) Delete

func (r *RedisCache) Delete(ctx context.Context, key string) error

func (*RedisCache) Get

func (r *RedisCache) Get(ctx context.Context, key string) (any, error)

func (*RedisCache) LoadAndDelete

func (r *RedisCache) LoadAndDelete(ctx context.Context, key string) (any, error)

func (*RedisCache) Set

func (r *RedisCache) Set(ctx context.Context, key string, val any, expiration time.Duration) error

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL