contract

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// 基础操作
	IsExist(ctx context.Context, key string) bool
	Get(ctx context.Context, key string) (string, error)
	Put(ctx context.Context, key string, value string, expiration time.Duration) error
	Delete(ctx context.Context, key string) error
	BatchDelete(ctx context.Context, prefix string) error

	// 高级操作
	GetWithTTL(ctx context.Context, key string) (string, time.Duration, error)
	Increment(ctx context.Context, key string, delta int64) (int64, error)
	Decrement(ctx context.Context, key string, delta int64) (int64, error)
	SetNX(ctx context.Context, key string, value string, expiration time.Duration) (bool, error)
	Expire(ctx context.Context, key string, expiration time.Duration) error
	Keys(ctx context.Context, pattern string) ([]string, error)
	FlushAll(ctx context.Context) error

	// 生命周期
	Close() error
}

Cache 基础缓存接口

type CacheStrategy

type CacheStrategy interface {
	// ShouldCache 是否应该缓存
	ShouldCache(key string, value interface{}) bool
	// GetTTL 获取TTL
	GetTTL(key string, value interface{}) time.Duration
	// GetCacheKey 获取缓存键
	GetCacheKey(prefix string, parts ...string) string
	// ShouldWarmUp 是否启用预热
	ShouldWarmUp() bool
}

CacheStrategy 缓存策略接口

type Serializer

type Serializer interface {
	Serialize(v interface{}) ([]byte, error)
	Deserialize(data []byte, v interface{}) error
	ContentType() string
}

Serializer 序列化器接口

type TypedCache

type TypedCache interface {
	GetObject(ctx context.Context, key string, obj interface{}) error
	PutObject(ctx context.Context, key string, obj interface{}, expiration time.Duration) error
	DeleteObject(ctx context.Context, key string) error
}

TypedCache 类型化缓存接口

Jump to

Keyboard shortcuts

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