Documentation
¶
Index ¶
- func NewSimpleAdapter() rbac.CacheAdapter
- type CacheAdapter
- type CacheAside
- type CacheConfig
- type CacheEvictionPolicy
- type CacheMetrics
- type CacheMonitor
- type CacheProtection
- type CacheStats
- type CacheStrategy
- type CacheStrategyBuilder
- func (b *CacheStrategyBuilder) Build() *CacheStrategy
- func (b *CacheStrategyBuilder) WithCompression(enabled bool) *CacheStrategyBuilder
- func (b *CacheStrategyBuilder) WithMaxSize(size int) *CacheStrategyBuilder
- func (b *CacheStrategyBuilder) WithPrefix(prefix string) *CacheStrategyBuilder
- func (b *CacheStrategyBuilder) WithTTL(cacheType string, ttl time.Duration) *CacheStrategyBuilder
- type CacheWarmup
- type Error
- type LFUPolicy
- type LRUPolicy
- type LoaderFunc
- type MetricsCollector
- func (c *MetricsCollector) GetHitRate(cacheType string) float64
- func (c *MetricsCollector) GetMetrics(cacheType string) *CacheMetrics
- func (c *MetricsCollector) RecordEvict(cacheType string)
- func (c *MetricsCollector) RecordHit(cacheType string)
- func (c *MetricsCollector) RecordMiss(cacheType string)
- func (c *MetricsCollector) RecordSet(cacheType string)
- type MultiLevelCache
- func (m *MultiLevelCache) Clear(ctx context.Context) error
- func (m *MultiLevelCache) Delete(ctx context.Context, key string) error
- func (m *MultiLevelCache) Get(ctx context.Context, key string) (interface{}, error)
- func (m *MultiLevelCache) Set(ctx context.Context, key string, value interface{}) error
- type SimpleAdapter
- type StoreAdapter
- type TTLCache
- type TTLItem
- type WriteBack
- type WriteThrough
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CacheAdapter ¶
type CacheAdapter interface {
Get(key string) (interface{}, error)
Set(key string, value interface{}, ttl time.Duration) error
Delete(key string) error
Exists(key string) bool
}
CacheAdapter 缓存适配器接口
type CacheAside ¶
type CacheAside struct {
// contains filtered or unexported fields
}
CacheAside 缓存旁路模式
type CacheConfig ¶
CacheConfig 缓存配置
type CacheEvictionPolicy ¶
type CacheEvictionPolicy interface {
Evict(cache *MultiLevelCache) error
}
CacheEvictionPolicy 缓存淘汰策略接口
type CacheMetrics ¶
CacheMetrics 缓存指标
type CacheMonitor ¶
type CacheMonitor struct {
// contains filtered or unexported fields
}
CacheMonitor 缓存监控
type CacheProtection ¶
type CacheProtection struct {
// contains filtered or unexported fields
}
CacheProtection 缓存保护机制
func NewCacheProtection ¶
func NewCacheProtection(cache *MultiLevelCache) *CacheProtection
NewCacheProtection 创建缓存保护
func (*CacheProtection) PreventCacheAvalanche ¶
func (p *CacheProtection) PreventCacheAvalanche(keys []string, ttl time.Duration) error
PreventCacheAvalanche 防止缓存雪崩
func (*CacheProtection) PreventCacheBreakdown ¶
func (p *CacheProtection) PreventCacheBreakdown(ctx context.Context, key string) (interface{}, error)
PreventCacheBreakdown 防止缓存击穿
func (*CacheProtection) PreventCachePenetration ¶
func (p *CacheProtection) PreventCachePenetration(ctx context.Context, key string) (interface{}, error)
PreventCachePenetration 防止缓存穿透
type CacheStats ¶
type CacheStats struct {
TotalHits int64
TotalMisses int64
TotalSets int64
TotalDeletes int64
CurrentSize int
HitRate float64
}
CacheStats 缓存统计
type CacheStrategy ¶
type CacheStrategy struct {
// contains filtered or unexported fields
}
CacheStrategy 缓存策略
func NewCacheStrategy ¶
func NewCacheStrategy(config CacheConfig) *CacheStrategy
NewCacheStrategy 创建缓存策略
type CacheStrategyBuilder ¶
type CacheStrategyBuilder struct {
// contains filtered or unexported fields
}
CacheStrategyBuilder 缓存策略构建器
func NewCacheStrategyBuilder ¶
func NewCacheStrategyBuilder() *CacheStrategyBuilder
NewCacheStrategyBuilder 创建构建器
func (*CacheStrategyBuilder) Build ¶
func (b *CacheStrategyBuilder) Build() *CacheStrategy
Build 构建策略
func (*CacheStrategyBuilder) WithCompression ¶
func (b *CacheStrategyBuilder) WithCompression(enabled bool) *CacheStrategyBuilder
WithCompression 启用压缩
func (*CacheStrategyBuilder) WithMaxSize ¶
func (b *CacheStrategyBuilder) WithMaxSize(size int) *CacheStrategyBuilder
WithMaxSize 设置最大大小
func (*CacheStrategyBuilder) WithPrefix ¶
func (b *CacheStrategyBuilder) WithPrefix(prefix string) *CacheStrategyBuilder
WithPrefix 设置前缀
func (*CacheStrategyBuilder) WithTTL ¶
func (b *CacheStrategyBuilder) WithTTL(cacheType string, ttl time.Duration) *CacheStrategyBuilder
WithTTL 设置 TTL
type CacheWarmup ¶
type CacheWarmup struct {
// contains filtered or unexported fields
}
CacheWarmup 缓存预热
func NewCacheWarmup ¶
func NewCacheWarmup(cache *MultiLevelCache, loader LoaderFunc) *CacheWarmup
NewCacheWarmup 创建缓存预热
type LFUPolicy ¶
type LFUPolicy struct {
// contains filtered or unexported fields
}
LFUPolicy LFU 淘汰策略
type LRUPolicy ¶
type LRUPolicy struct {
// contains filtered or unexported fields
}
LRUPolicy LRU 淘汰策略
type MetricsCollector ¶
type MetricsCollector struct {
// contains filtered or unexported fields
}
MetricsCollector 指标收集器
func (*MetricsCollector) GetHitRate ¶
func (c *MetricsCollector) GetHitRate(cacheType string) float64
GetHitRate 获取命中率
func (*MetricsCollector) GetMetrics ¶
func (c *MetricsCollector) GetMetrics(cacheType string) *CacheMetrics
GetMetrics 获取指标
func (*MetricsCollector) RecordEvict ¶
func (c *MetricsCollector) RecordEvict(cacheType string)
RecordEvict 记录驱逐
func (*MetricsCollector) RecordHit ¶
func (c *MetricsCollector) RecordHit(cacheType string)
RecordHit 记录命中
func (*MetricsCollector) RecordMiss ¶
func (c *MetricsCollector) RecordMiss(cacheType string)
RecordMiss 记录未命中
func (*MetricsCollector) RecordSet ¶
func (c *MetricsCollector) RecordSet(cacheType string)
RecordSet 记录设置
type MultiLevelCache ¶
type MultiLevelCache struct {
L1 *sync.Map // 本地内存
L2 CacheAdapter // 二级缓存 (Redis 或其他)
L3 LoaderFunc // 三级缓存 (数据库加载器)
}
MultiLevelCache 多级缓存
func NewMultiLevelCache ¶
func NewMultiLevelCache(l2 CacheAdapter, l3 LoaderFunc) *MultiLevelCache
NewMultiLevelCache 创建多级缓存
func (*MultiLevelCache) Clear ¶
func (m *MultiLevelCache) Clear(ctx context.Context) error
Clear 清空缓存
func (*MultiLevelCache) Delete ¶
func (m *MultiLevelCache) Delete(ctx context.Context, key string) error
Delete 删除缓存
type SimpleAdapter ¶
type SimpleAdapter struct {
// contains filtered or unexported fields
}
SimpleAdapter 简单的内存缓存适配器 实现 frame-core/auth/rbac.CacheAdapter 接口
type StoreAdapter ¶
StoreAdapter 存储适配器
type WriteBack ¶
type WriteBack struct {
// contains filtered or unexported fields
}
WriteBack 写回
func NewWriteBack ¶
func NewWriteBack(cache *MultiLevelCache, store StoreAdapter, flushInterval time.Duration) *WriteBack
NewWriteBack 创建写回
type WriteThrough ¶
type WriteThrough struct {
// contains filtered or unexported fields
}
WriteThrough 写穿透
func NewWriteThrough ¶
func NewWriteThrough(cache *MultiLevelCache, store StoreAdapter) *WriteThrough
NewWriteThrough 创建写穿透