cache

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCacheDriver added in v0.5.0

func NewCacheDriver(driverName string) contracts.Cache

NewCacheDriver 创建缓存驱动

Types

type SFGroup added in v0.5.0

type SFGroup[T any] struct {
	// contains filtered or unexported fields
}

func (*SFGroup[T]) Do added in v0.5.0

func (s *SFGroup[T]) Do(ctx context.Context, key string, fn func() (T, error)) (T, error)

func (*SFGroup[T]) Forget added in v0.5.0

func (s *SFGroup[T]) Forget(key string)

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]) Delete added in v0.5.0

func (c *TypedCache[T]) Delete(ctx context.Context, base string, tags ...string) error

Delete 删除缓存

func (*TypedCache[T]) Get added in v0.5.0

func (c *TypedCache[T]) Get(ctx context.Context, base string, tags ...string) (T, bool, error)

Get 从缓存获取

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]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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