cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

包 cache 提供内部缓存管理能力。

该包包含 AgentFlow 在 `internal/cache` 目录下的核心实现。

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = fmt.Errorf("cache miss")

ErrCacheMiss 缓存未命中错误

Functions

func IsCacheMiss

func IsCacheMiss(err error) bool

IsCacheMiss 判断是否为缓存未命中错误

Types

type Config

type Config struct {
	// Redis 地址
	Addr string `yaml:"addr" json:"addr"`

	// 密码
	Password string `yaml:"password" json:"password"`

	// 数据库编号
	DB int `yaml:"db" json:"db"`

	// 默认过期时间
	DefaultTTL time.Duration `yaml:"default_ttl" json:"default_ttl"`

	// 最大重试次数
	MaxRetries int `yaml:"max_retries" json:"max_retries"`

	// 连接池大小
	PoolSize int `yaml:"pool_size" json:"pool_size"`

	// 最小空闲连接数
	MinIdleConns int `yaml:"min_idle_conns" json:"min_idle_conns"`

	// 健康检查间隔
	HealthCheckInterval time.Duration `yaml:"health_check_interval" json:"health_check_interval"`
}

Config 缓存配置

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 返回默认缓存配置

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 缓存管理器

func NewManager

func NewManager(config Config, logger *zap.Logger) (*Manager, error)

NewManager 创建缓存管理器

func (*Manager) Close

func (m *Manager) Close() error

Close 关闭缓存管理器

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, keys ...string) error

Delete 删除缓存值

func (*Manager) Exists

func (m *Manager) Exists(ctx context.Context, keys ...string) (int64, error)

Exists 检查键是否存在

func (*Manager) Expire

func (m *Manager) Expire(ctx context.Context, key string, ttl time.Duration) error

Expire 设置键的过期时间

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, key string) (string, error)

Get 获取缓存值

func (*Manager) GetJSON

func (m *Manager) GetJSON(ctx context.Context, key string, dest any) error

GetJSON 获取 JSON 缓存值

func (*Manager) GetStats

func (m *Manager) GetStats(ctx context.Context) (*Stats, error)

GetStats 获取缓存统计信息

func (*Manager) Ping

func (m *Manager) Ping(ctx context.Context) error

Ping 检查 Redis 连接

func (*Manager) Set

func (m *Manager) Set(ctx context.Context, key string, value string, ttl time.Duration) error

Set 设置缓存值

func (*Manager) SetJSON

func (m *Manager) SetJSON(ctx context.Context, key string, value any, ttl time.Duration) error

SetJSON 设置 JSON 缓存值

type Stats

type Stats struct {
	Hits        uint64 `json:"hits"`
	Misses      uint64 `json:"misses"`
	Keys        int64  `json:"keys"`
	UsedMemory  int64  `json:"used_memory"`
	MaxMemory   int64  `json:"max_memory"`
	Connections int    `json:"connections"`
}

Stats 缓存统计信息

Jump to

Keyboard shortcuts

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