Documentation
¶
Index ¶
- Variables
- type Cache
- type CacheStats
- type MemoryCache
- func (c *MemoryCache) Clear(ctx context.Context) error
- func (c *MemoryCache) Close() error
- func (c *MemoryCache) Delete(ctx context.Context, key string) error
- func (c *MemoryCache) Exists(ctx context.Context, key string) bool
- func (c *MemoryCache) Get(ctx context.Context, key string, dest interface{}) error
- func (c *MemoryCache) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (c *MemoryCache) Stats() CacheStats
- type MemoryCacheConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrKeyNotFound = errors.New("key not found") ErrCacheClosed = errors.New("cache is closed") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
Get(ctx context.Context, key string, dest interface{}) error
Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
Delete(ctx context.Context, key string) error
Exists(ctx context.Context, key string) bool
Clear(ctx context.Context) error
Stats() CacheStats
Close() error
}
Cache 缓存接口
type CacheStats ¶
type CacheStats struct {
Hits int64 `json:"hits"`
Misses int64 `json:"misses"`
Sets int64 `json:"sets"`
Deletes int64 `json:"deletes"`
Errors int64 `json:"errors"`
HitRatio float64 `json:"hit_ratio"`
TotalKeys int `json:"total_keys"`
MemoryUsage int64 `json:"memory_usage_bytes"`
}
CacheStats 缓存统计信息
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache 内存缓存实现
func NewMemoryCache ¶
func NewMemoryCache(config MemoryCacheConfig) *MemoryCache
NewMemoryCache 创建内存缓存
func (*MemoryCache) Delete ¶
func (c *MemoryCache) Delete(ctx context.Context, key string) error
Delete 删除缓存值
func (*MemoryCache) Exists ¶
func (c *MemoryCache) Exists(ctx context.Context, key string) bool
Exists 检查key是否存在
func (*MemoryCache) Get ¶
func (c *MemoryCache) Get(ctx context.Context, key string, dest interface{}) error
Get 获取缓存值
type MemoryCacheConfig ¶
type MemoryCacheConfig struct {
MaxSize int64 // 最大内存使用量(字节)
CleanupInterval time.Duration // 清理间隔
}
MemoryCacheConfig 内存缓存配置
Click to show internal directories.
Click to hide internal directories.