Documentation
¶
Index ¶
- func NewCacheDriver(driverName string) contracts.Cache
- type SFGroup
- type TypedCache
- func (c *TypedCache[T]) BatchDeleteByPrefix(ctx context.Context, prefix string) error
- func (c *TypedCache[T]) Delete(ctx context.Context, base string, tags ...string) error
- func (c *TypedCache[T]) Get(ctx context.Context, base string, tags ...string) (T, bool, error)
- func (c *TypedCache[T]) GetOrLoad(ctx context.Context, base string, ttl time.Duration, ...) (T, error)
- func (c *TypedCache[T]) InvalidateTags(ctx context.Context, tags ...string) error
- func (c *TypedCache[T]) Set(ctx context.Context, base string, val T, ttl time.Duration, tags ...string) error
- func (c *TypedCache[T]) WithDefaultTTL(ttl time.Duration) *TypedCache[T]
- func (c *TypedCache[T]) WithSerializer(serializer contracts.Serializer[T]) *TypedCache[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCacheDriver ¶ added in v0.5.0
NewCacheDriver 创建缓存驱动
Types ¶
type SFGroup ¶ added in v0.5.0
type SFGroup[T any] struct { // contains filtered or unexported fields }
type TypedCache ¶ added in v0.5.0
type TypedCache[T any] struct { // contains filtered or unexported fields }
TypedCache 基于泛型的强类型缓存,支持标签失效与单航班防击穿
func NewTypedCache ¶ added in v0.5.0
func NewTypedCache[T any](namespace string, cache contracts.Cache) *TypedCache[T]
NewTypedCache 创建类型缓存
func NewTypedCacheWith ¶ added in v0.5.0
func NewTypedCacheWith[T any](driverName, namespace string, ttl time.Duration) *TypedCache[T]
NewTypedCacheWith 优雅构建 TypedCache,包含默认 TTL 与序列化器选择 driverName: "memory" 或 "redis" namespace: 缓存命名空间前缀 ttl: 默认TTL(<=0 则不设置默认TTL)
func (*TypedCache[T]) BatchDeleteByPrefix ¶ added in v0.5.0
func (c *TypedCache[T]) BatchDeleteByPrefix(ctx context.Context, prefix string) error
BatchDeleteByPrefix 前缀删除(用于紧急清理,或老组件兼容)
func (*TypedCache[T]) GetOrLoad ¶ added in v0.5.0
func (c *TypedCache[T]) GetOrLoad(ctx context.Context, base string, ttl time.Duration, loader func(context.Context) (T, error), tags ...string) (T, error)
GetOrLoad 旁路缓存 + 单航班防击穿
func (*TypedCache[T]) InvalidateTags ¶ added in v0.5.0
func (c *TypedCache[T]) InvalidateTags(ctx context.Context, tags ...string) error
InvalidateTags 标签失效(版本 +1),O(1) 完成,无需扫描
func (*TypedCache[T]) Set ¶ added in v0.5.0
func (c *TypedCache[T]) Set(ctx context.Context, base string, val T, ttl time.Duration, tags ...string) error
Set 写入缓存
func (*TypedCache[T]) WithDefaultTTL ¶ added in v0.5.0
func (c *TypedCache[T]) WithDefaultTTL(ttl time.Duration) *TypedCache[T]
func (*TypedCache[T]) WithSerializer ¶ added in v0.5.0
func (c *TypedCache[T]) WithSerializer(serializer contracts.Serializer[T]) *TypedCache[T]
Click to show internal directories.
Click to hide internal directories.