Documentation ¶
Index ¶
- type CacheManager
- func (cm *CacheManager) Delete(key string) error
- func (cm *CacheManager) Get(key string) ([]byte, bool, error)
- func (cm *CacheManager) GetStats() (memoryRequestQPS, memoryHitQPS, redisRequestQPS, redisHitQPS float64)
- func (cm *CacheManager) Keys(prefix string) (keys []interface{}, err error)
- func (cm *CacheManager) PrewarmCache(keys []string) error
- func (cm *CacheManager) PrewarmCacheFromPattern(pattern string) error
- func (cm *CacheManager) Set(key string, value []byte, ttl time.Duration) error
- func (cm *CacheManager) WithErrorHandler(handler ErrorHandler) *CacheManager
- type CacheStats
- type CacheStorage
- type Config
- type DistributedCache
- type ErrorHandler
- type FreeCache
- type RedisCache
- func (rc *RedisCache) Delete(key string) error
- func (rc *RedisCache) Get(key string) ([]byte, bool, error)
- func (rc *RedisCache) GetStats() (float64, float64)
- func (rc *RedisCache) Keys(prefix string) ([]string, error)
- func (rc *RedisCache) Set(key string, value []byte, ttl time.Duration) error
- func (rc *RedisCache) SubscribeExpiryEvents(callback func(string))
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
}
CacheManager 结构体,管理内存缓存和 Redis 缓存
func NewCacheManager ¶
func NewCacheManager(config *configs.CacheConfig) *CacheManager
NewCacheManager 创建 CacheManager 实例
func (*CacheManager) GetStats ¶
func (cm *CacheManager) GetStats() (memoryRequestQPS, memoryHitQPS, redisRequestQPS, redisHitQPS float64)
GetStats 获取缓存统计数据
func (*CacheManager) Keys ¶
func (cm *CacheManager) Keys(prefix string) (keys []interface{}, err error)
Keys 获取缓存中指定前缀的key列表,如果prefix为空则返回所有key
func (*CacheManager) PrewarmCache ¶
func (cm *CacheManager) PrewarmCache(keys []string) error
PrewarmCache 预热缓存
func (*CacheManager) PrewarmCacheFromPattern ¶
func (cm *CacheManager) PrewarmCacheFromPattern(pattern string) error
PrewarmCacheFromPattern 从 Redis 模式匹配预热缓存
func (*CacheManager) WithErrorHandler ¶
func (cm *CacheManager) WithErrorHandler(handler ErrorHandler) *CacheManager
WithErrorHandler 设置错误处理器
type CacheStats ¶
type CacheStats struct {
// contains filtered or unexported fields
}
CacheStats 结构体,用于记录缓存统计信息
func (*CacheStats) GetStats ¶
func (cs *CacheStats) GetStats() (requestQPS, hitQPS float64)
GetStats 获取统计信息
func (*CacheStats) IncrementHitCount ¶
func (cs *CacheStats) IncrementHitCount()
IncrementHitCount 增加命中计数
func (*CacheStats) IncrementRequestCount ¶
func (cs *CacheStats) IncrementRequestCount()
IncrementRequestCount 增加请求计数
type CacheStorage ¶
type CacheStorage interface { Set(key string, value []byte, ttl time.Duration) error Get(key string) ([]byte, bool, error) Delete(key string) error }
CacheStorage 定义缓存存储接口
type Config ¶
type Config struct { MemoryCacheSize int // 内存缓存大小(字节) RedisAddr string // Redis 地址 RedisPassword string // Redis 密码 RedisDB int // Redis 数据库编号 RedisPrefix string // Redis 键前缀 }
Config 结构体用于存储缓存系统的配置
type DistributedCache ¶
type DistributedCache interface { CacheStorage Publish(channel string, message []byte) error Subscribe(channel string) (<-chan []byte, error) }
DistributedCache 定义分布式缓存接口
type FreeCache ¶
type FreeCache struct {
// contains filtered or unexported fields
}
FreeCache 结构体,实现内存缓存
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache 结构体,实现 Redis 缓存
func NewRedisCache ¶
func NewRedisCache(config *configs.CacheConfig) *RedisCache
NewRedisCache 创建 RedisCache 实例
func (*RedisCache) Get ¶
func (rc *RedisCache) Get(key string) ([]byte, bool, error)
Get 从 Redis 获取数据
func (*RedisCache) GetStats ¶
func (rc *RedisCache) GetStats() (float64, float64)
GetStats 获取 Redis 缓存的统计信息
func (*RedisCache) Keys ¶
func (rc *RedisCache) Keys(prefix string) ([]string, error)
Keys 获取Redis中指定前缀的key列表
func (*RedisCache) SubscribeExpiryEvents ¶
func (rc *RedisCache) SubscribeExpiryEvents(callback func(string))
SubscribeExpiryEvents 订阅 Redis 键过期事件
Click to show internal directories.
Click to hide internal directories.