cache

package
v0.10.13 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLocalCacheItems = 0 //local cache items. it's important for performance & if redis failed.
View Source
var DefaultTimeout time.Duration = 30 * time.Minute

Functions

func NewRedisClient added in v0.9.0

func NewRedisClient(opts *redis.Options, logger *zap.Logger) *redis.Client

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any]() *Cache[T]

func NewWithTimeout added in v0.6.3

func NewWithTimeout[T any](dur time.Duration) *Cache[T]

func (*Cache[T]) Del added in v0.10.5

func (ct *Cache[T]) Del(key string) error

func (*Cache[T]) Get

func (ct *Cache[T]) Get(key string) (T, bool)

func (*Cache[T]) Keys added in v0.10.4

func (ct *Cache[T]) Keys() []string

func (*Cache[T]) Set

func (ct *Cache[T]) Set(key string, value T)

type CacheConfig added in v0.10.6

type CacheConfig struct {
	Disalbed   bool
	LocalItems int
	TTL        time.Duration
}

type CacheProvider added in v0.8.2

type CacheProvider[T any] interface {
	Set(key string, value T)
	Get(key string) (T, bool)
	Del(key string) error
	Keys() []string
}

func NewCacheProvider added in v0.8.2

func NewCacheProvider[T any](t time.Duration) CacheProvider[T]

type CacheRam added in v0.8.2

type CacheRam[T any] struct {
	// contains filtered or unexported fields
}

func NewRAMCacheProvider added in v0.10.0

func NewRAMCacheProvider[T any](t time.Duration) *CacheRam[T]

func (*CacheRam[T]) Del added in v0.10.5

func (cc *CacheRam[T]) Del(key string) error

func (*CacheRam[T]) Get added in v0.8.2

func (cc *CacheRam[T]) Get(key string) (T, bool)

func (*CacheRam[T]) Keys added in v0.10.4

func (cc *CacheRam[T]) Keys() []string

func (*CacheRam[T]) Set added in v0.8.2

func (cc *CacheRam[T]) Set(key string, value T)

type CacheWithTTL added in v0.10.4

type CacheWithTTL interface {
	GetTTL() time.Duration
}

type CachedList added in v0.9.1

type CachedList[T any] interface {
	Append(ctx context.Context, key string, raw ...T) error
	GetAll(ctx context.Context, key string) ([]T, error)
	Del(ctx context.Context, key string) error
}

func NewCachedList added in v0.9.1

func NewCachedList[T any](prefix string, dur time.Duration) CachedList[T]

type CachedListRedis added in v0.9.1

type CachedListRedis[T any] struct {
	Logger  *zap.Logger
	Client  *redis.Client
	Prefix  string
	Timeout time.Duration
}

func (*CachedListRedis[T]) Append added in v0.9.1

func (ll *CachedListRedis[T]) Append(ctx context.Context, key string, raw ...T) error

func (*CachedListRedis[T]) Del added in v0.9.1

func (ll *CachedListRedis[T]) Del(ctx context.Context, key string) error

func (*CachedListRedis[T]) GetAll added in v0.9.1

func (ll *CachedListRedis[T]) GetAll(ctx context.Context, key string) ([]T, error)

type DisabledCache added in v0.10.6

type DisabledCache[T any] struct {
	// contains filtered or unexported fields
}

func (*DisabledCache[T]) Del added in v0.10.6

func (dd *DisabledCache[T]) Del(key string) error

func (*DisabledCache[T]) Get added in v0.10.6

func (dd *DisabledCache[T]) Get(key string) (T, bool)

func (*DisabledCache[T]) Keys added in v0.10.6

func (dd *DisabledCache[T]) Keys() []string

func (*DisabledCache[T]) Set added in v0.10.6

func (dd *DisabledCache[T]) Set(key string, value T)

type Hash added in v0.10.3

type Hash interface {
	Existed(ctx context.Context, key string) (bool, error)
	SetTTL(ctx context.Context, key string, ttl time.Duration)
	GetValues(ctx context.Context, key string, fields ...string) ([]any, error)
	SetValues(ctx context.Context, key string, values map[string]any) error
}

func NewRedisHashService added in v0.10.2

func NewRedisHashService(client *redis.Client, logger *zap.Logger) Hash

type RedisConfig added in v0.9.0

type RedisConfig struct {
	Host       string
	Port       uint
	Account    string
	Passwd     string
	Caroot     string // where is the ca pem file.
	Tls        bool   //TLS enabled ?
	DB         int    // 0: dev, 1: uat, 3: prd
	PoolSize   int
	MinIdle    int
	ClientName string
}

type RedisHashService added in v0.10.2

type RedisHashService struct {
	Client *redis.Client
	Logger *zap.Logger
}

func (*RedisHashService) Existed added in v0.10.6

func (rs *RedisHashService) Existed(ctx context.Context, key string) (bool, error)

func (*RedisHashService) GetValues added in v0.10.2

func (rs *RedisHashService) GetValues(ctx context.Context, key string, fields ...string) ([]any, error)

func (*RedisHashService) SetTTL added in v0.10.6

func (rs *RedisHashService) SetTTL(ctx context.Context, key string, ttl time.Duration)

func (*RedisHashService) SetValues added in v0.10.2

func (rs *RedisHashService) SetValues(ctx context.Context, key string, values map[string]any) error

type RedisProvider added in v0.9.0

type RedisProvider[T any] struct {
	Client *redis.Client
	// contains filtered or unexported fields
}

func (*RedisProvider[T]) Del added in v0.10.5

func (r *RedisProvider[T]) Del(key string) error

func (*RedisProvider[T]) Get added in v0.9.0

func (r *RedisProvider[T]) Get(key string) (T, bool)

Get implements CacheProvider.

func (*RedisProvider[T]) Keys added in v0.10.4

func (r *RedisProvider[T]) Keys() []string

func (*RedisProvider[T]) Set added in v0.9.0

func (r *RedisProvider[T]) Set(key string, value T)

Set implements CacheProvider.

type WithKey added in v0.9.1

type WithKey interface {
	Key() string
}

Jump to

Keyboard shortcuts

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