cache

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	ModuleName string    `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`
	Type       CacheType `mapstructure:"type" yaml:"type" json:"type"`
	Enabled    bool      `mapstructure:"enabled" yaml:"enabled" json:"enabled"`

	// 基础配置
	DefaultTTL time.Duration `mapstructure:"default-ttl" yaml:"default-ttl" json:"defaultTtl"`
	KeyPrefix  string        `mapstructure:"key-prefix" yaml:"key-prefix" json:"keyPrefix"`
	Serializer string        `mapstructure:"serializer" yaml:"serializer" json:"serializer"` // json, gob, msgpack

	// 各种缓存实现的配置(按需使用)
	Memory    Memory    `mapstructure:"memory" yaml:"memory" json:"memory"`
	Ristretto Ristretto `mapstructure:"ristretto" yaml:"ristretto" json:"ristretto"`
	Redis     Redis     `mapstructure:"redis" yaml:"redis" json:"redis"`
	Sharded   Sharded   `mapstructure:"sharded" yaml:"sharded" json:"sharded"`
	TwoLevel  TwoLevel  `mapstructure:"two-level" yaml:"two-level" json:"twoLevel"`
	Expiring  Expiring  `mapstructure:"expiring" yaml:"expiring" json:"expiring"`
}

Cache 总缓存配置

func Default

func Default() *Cache

Default 返回默认缓存配置的指针,支持链式调用

func DefaultCache

func DefaultCache() Cache

DefaultCache 返回默认缓存配置

func NewCache

func NewCache(opt *Cache) *Cache

NewCache 创建一个新的 Cache 实例

func (*Cache) Clone

func (c *Cache) Clone() internal.Configurable

Clone 返回 Cache 配置的副本

func (*Cache) Get

func (c *Cache) Get() interface{}

Get 返回 Cache 配置的所有字段

func (*Cache) GetDefaultTTL

func (c *Cache) GetDefaultTTL() time.Duration

GetDefaultTTL 获取默认TTL

func (*Cache) GetKeyPrefix

func (c *Cache) GetKeyPrefix() string

GetKeyPrefix 获取键前缀

func (*Cache) GetModuleName

func (c *Cache) GetModuleName() string

GetModuleName 返回模块名称

func (*Cache) GetSerializer

func (c *Cache) GetSerializer() string

GetSerializer 获取序列化器类型

func (*Cache) GetType

func (c *Cache) GetType() CacheType

GetType 获取缓存类型

func (*Cache) IsEnabled

func (c *Cache) IsEnabled() bool

IsEnabled 检查缓存是否启用

func (*Cache) Set

func (c *Cache) Set(data interface{})

Set 更新 Cache 配置的字段

func (*Cache) Validate

func (c *Cache) Validate() error

Validate 验证配置是否有效

func (*Cache) WithDefaultTTL

func (c *Cache) WithDefaultTTL(ttl time.Duration) *Cache

WithDefaultTTL 设置默认TTL

func (*Cache) WithEnabled

func (c *Cache) WithEnabled(enabled bool) *Cache

WithEnabled 设置是否启用缓存

func (*Cache) WithExpiring

func (c *Cache) WithExpiring(expiring Expiring) *Cache

WithExpiring 设置过期缓存配置

func (*Cache) WithKeyPrefix

func (c *Cache) WithKeyPrefix(prefix string) *Cache

WithKeyPrefix 设置键前缀

func (*Cache) WithMemory

func (c *Cache) WithMemory(memory Memory) *Cache

WithMemory 设置内存缓存配置

func (*Cache) WithModuleName

func (c *Cache) WithModuleName(moduleName string) *Cache

WithModuleName 设置模块名称

func (*Cache) WithRedis

func (c *Cache) WithRedis(redis Redis) *Cache

WithRedis 设置Redis缓存配置

func (*Cache) WithRistretto

func (c *Cache) WithRistretto(ristretto Ristretto) *Cache

WithRistretto 设置Ristretto缓存配置

func (*Cache) WithSerializer

func (c *Cache) WithSerializer(serializer string) *Cache

WithSerializer 设置序列化器

func (*Cache) WithSharded

func (c *Cache) WithSharded(sharded Sharded) *Cache

WithSharded 设置分片缓存配置

func (*Cache) WithTwoLevel

func (c *Cache) WithTwoLevel(twoLevel TwoLevel) *Cache

WithTwoLevel 设置二级缓存配置

func (*Cache) WithType

func (c *Cache) WithType(cacheType CacheType) *Cache

WithType 设置缓存类型

type CacheType

type CacheType string

CacheType 缓存类型

const (
	CacheTypeMemory    CacheType = "memory"    // 内存缓存(LRU)
	CacheTypeRistretto CacheType = "ristretto" // 高性能缓存
	CacheTypeRedis     CacheType = "redis"     // Redis缓存
	CacheTypeSharded   CacheType = "sharded"   // 分片缓存
	CacheTypeTwoLevel  CacheType = "two-level" // 二级缓存
	CacheTypeExpiring  CacheType = "expiring"  // 过期缓存
)

type Expiring

type Expiring struct {
	ModuleName       string        `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                     // 模块名
	CleanupInterval  time.Duration `mapstructure:"cleanup-interval" yaml:"cleanup-interval" json:"cleanupInterval"`      // 清理间隔
	DefaultTTL       time.Duration `mapstructure:"default-ttl" yaml:"default-ttl" json:"defaultTtl"`                     // 默认TTL
	MaxSize          int           `mapstructure:"max-size" yaml:"max-size" json:"maxSize"`                              // 最大大小
	EvictionPolicy   string        `mapstructure:"eviction-policy" yaml:"eviction-policy" json:"evictionPolicy"`         // 驱逐策略: lru, lfu, fifo
	EnableLazyExpiry bool          `mapstructure:"enable-lazy-expiry" yaml:"enable-lazy-expiry" json:"enableLazyExpiry"` // 启用懒惰过期
	MaxMemoryUsage   int64         `mapstructure:"max-memory-usage" yaml:"max-memory-usage" json:"maxMemoryUsage"`       // 最大内存使用量(字节)
}

Expiring 过期缓存配置

func DefaultExpiring

func DefaultExpiring() *Expiring

DefaultExpiring 返回默认过期缓存配置的指针,支持链式调用

func DefaultExpiringConfig

func DefaultExpiringConfig() Expiring

DefaultExpiringConfig 返回默认过期缓存配置

func NewExpiring

func NewExpiring(opt *Expiring) *Expiring

NewExpiring 创建一个新的 Expiring 实例

func (*Expiring) Clone

func (e *Expiring) Clone() internal.Configurable

Clone 返回 Expiring 配置的副本

func (*Expiring) Get

func (e *Expiring) Get() interface{}

Get 返回 Expiring 配置的所有字段

func (*Expiring) Set

func (e *Expiring) Set(data interface{})

Set 更新 Expiring 配置的字段

func (*Expiring) Validate

func (e *Expiring) Validate() error

Validate 验证过期缓存配置

type Memory

type Memory struct {
	ModuleName  string        `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                     // 模块名
	Capacity    int           `mapstructure:"capacity" yaml:"capacity" json:"capacity" validate:"min=1"`            // 缓存容量
	DefaultTTL  time.Duration `mapstructure:"default-ttl" yaml:"default-ttl" json:"defaultTtl"`                     // 默认过期时间
	CleanupSize int           `mapstructure:"cleanup-size" yaml:"cleanup-size" json:"cleanupSize" validate:"min=0"` // 清理大小
	MaxSize     int           `mapstructure:"max-size" yaml:"max-size" json:"maxSize" validate:"min=0"`             // 最大大小
}

Memory 内存缓存配置

func DefaultMemory

func DefaultMemory() *Memory

DefaultMemory 返回默认内存缓存配置的指针,支持链式调用

func DefaultMemoryConfig

func DefaultMemoryConfig() Memory

DefaultMemoryConfig 返回默认内存缓存配置

func NewMemory

func NewMemory(opt *Memory) *Memory

NewMemory 创建一个新的 Memory 实例

func (*Memory) Clone

func (m *Memory) Clone() internal.Configurable

Clone 返回 Memory 配置的副本

func (*Memory) Get

func (m *Memory) Get() interface{}

Get 返回 Memory 配置的所有字段

func (*Memory) Set

func (m *Memory) Set(data interface{})

Set 更新 Memory 配置的字段

func (*Memory) Validate

func (m *Memory) Validate() error

Validate 验证内存缓存配置

func (*Memory) WithCapacity

func (m *Memory) WithCapacity(capacity int) *Memory

WithCapacity 设置缓存容量

func (*Memory) WithCleanupSize

func (m *Memory) WithCleanupSize(cleanupSize int) *Memory

WithCleanupSize 设置清理大小

func (*Memory) WithDefaultTTL

func (m *Memory) WithDefaultTTL(defaultTTL time.Duration) *Memory

WithDefaultTTL 设置默认过期时间

func (*Memory) WithMaxSize

func (m *Memory) WithMaxSize(maxSize int) *Memory

WithMaxSize 设置最大大小

func (*Memory) WithModuleName

func (m *Memory) WithModuleName(moduleName string) *Memory

WithModuleName 设置模块名称

type Redis

type Redis struct {
	ModuleName string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"` // 模块名
	// 兼容原有配置
	Addr string `mapstructure:"addr" yaml:"addr" json:"addr" validate:"url"` // Redis 数据服务器 IP 和端口(兼容旧版)
	// 新增增强配置
	Addrs                 []string      `mapstructure:"addrs" yaml:"addrs" json:"addrs"`                                                     // Redis服务器地址列表(集群模式)
	ClientName            string        `mapstructure:"client-name" yaml:"client-name" json:"clientName"`                                    // 客户端名称,执行 CLIENT SETNAME
	Protocol              int           `mapstructure:"protocol" yaml:"protocol" json:"protocol"`                                            // RESP 协议版本(2 或 3)
	Username              string        `mapstructure:"username" yaml:"username" json:"username"`                                            // 用户名
	Password              string        `mapstructure:"password" yaml:"password" json:"password"`                                            // 连接密码
	SentinelUsername      string        `mapstructure:"sentinel-username" yaml:"sentinel-username" json:"sentinelUsername"`                  // 哨兵认证用户名
	SentinelPassword      string        `mapstructure:"sentinel-password" yaml:"sentinel-password" json:"sentinelPassword"`                  // 哨兵认证密码
	DB                    int           `mapstructure:"db" yaml:"db" json:"db" validate:"min=0"`                                             // 指定连接的数据库,默认连数据库 0
	MaxRetries            int           `mapstructure:"max-retries" yaml:"max-retries" json:"maxRetries" validate:"min=0"`                   // 最大重试次数,最小值为 0
	MaxRedirects          int           `mapstructure:"max-redirects" yaml:"max-redirects" json:"maxRedirects" validate:"min=0"`             // 集群模式最大重定向次数
	PoolSize              int           `mapstructure:"pool-size" yaml:"pool-size" json:"poolSize" validate:"min=1"`                         // 连接池大小,最小值为 1
	MaxActiveConns        int           `mapstructure:"max-active-conns" yaml:"max-active-conns" json:"maxActiveConns" validate:"min=0"`     // 最大活跃连接数,0 表示不限制
	MinIdleConns          int           `mapstructure:"min-idle-conns" yaml:"min-idle-conns" json:"minIdleConns" validate:"min=0"`           // 最小空闲连接数,最小值为 0
	MaxIdleConns          int           `mapstructure:"max-idle-conns" yaml:"max-idle-conns" json:"maxIdleConns" validate:"min=0"`           // 最大空闲连接数,最小值为 0
	ReadBufferSize        int           `mapstructure:"read-buffer-size" yaml:"read-buffer-size" json:"readBufferSize" validate:"min=0"`     // 读缓冲区大小(字节),默认 32KB
	WriteBufferSize       int           `mapstructure:"write-buffer-size" yaml:"write-buffer-size" json:"writeBufferSize" validate:"min=0"`  // 写缓冲区大小(字节),默认 32KB
	MaxConnAge            time.Duration `mapstructure:"max-conn-age" yaml:"max-conn-age" json:"maxConnAge"`                                  // 连接最大存活时间
	DialTimeout           time.Duration `mapstructure:"dial-timeout" yaml:"dial-timeout" json:"dialTimeout"`                                 // 连接超时
	PoolTimeout           time.Duration `mapstructure:"pool-timeout" yaml:"pool-timeout" json:"poolTimeout"`                                 // 连接池超时
	IdleTimeout           time.Duration `mapstructure:"idle-timeout" yaml:"idle-timeout" json:"idleTimeout"`                                 // 空闲超时
	ReadTimeout           time.Duration `mapstructure:"read-timeout" yaml:"read-timeout" json:"readTimeout"`                                 // 读取超时
	WriteTimeout          time.Duration `mapstructure:"write-timeout" yaml:"write-timeout" json:"writeTimeout"`                              // 写入超时
	MinRetryBackoff       time.Duration `mapstructure:"min-retry-backoff" yaml:"min-retry-backoff" json:"minRetryBackoff" validate:"min=0"`  // 最小重试间隔
	MaxRetryBackoff       time.Duration `mapstructure:"max-retry-backoff" yaml:"max-retry-backoff" json:"maxRetryBackoff" validate:"min=0"`  // 最大重试间隔
	ContextTimeoutEnabled bool          `mapstructure:"context-timeout-enabled" yaml:"context-timeout-enabled" json:"contextTimeoutEnabled"` // 是否用 context 控制命令超时
	ReadOnly              bool          `mapstructure:"read-only" yaml:"read-only" json:"readOnly"`                                          // 集群模式只读(从节点读)
	ClusterMode           bool          `mapstructure:"cluster-mode" yaml:"cluster-mode" json:"clusterMode"`                                 // 是否集群模式(单地址集群也生效,映射到 go-redis IsClusterMode)
	MasterName            string        `mapstructure:"master-name" yaml:"master-name" json:"masterName"`                                    // 哨兵模式 master 名称,非空时启用哨兵模式
	RouteByLatency        bool          `mapstructure:"route-by-latency" yaml:"route-by-latency" json:"routeByLatency"`                      // 集群模式按延迟路由(只读从节点)
	RouteRandomly         bool          `mapstructure:"route-randomly" yaml:"route-randomly" json:"routeRandomly"`                           // 集群模式随机路由(只读从节点)
}

Redis 结构体用于配置 Redis 相关参数(增强版配置) 字段与 go-redis v9 UniversalOptions 对齐,通过 redis.go 映射到 UniversalOptions

func DefaultRedis

func DefaultRedis() *Redis

DefaultRedisConfig 返回默认Redis配置的指针,支持链式调用

func DefaultRedisConfig

func DefaultRedisConfig() Redis

DefaultRedisConfig 返回默认Redis配置

func NewRedis

func NewRedis(opt *Redis) *Redis

NewRedis 创建一个新的 Redis 实例

func (*Redis) Clone

func (r *Redis) Clone() internal.Configurable

Clone 返回 Redis 配置的副本

func (*Redis) Get

func (r *Redis) Get() interface{}

Get 返回 Redis 配置的所有字段

func (*Redis) Set

func (r *Redis) Set(data interface{})

Set 更新 Redis 配置的字段

func (*Redis) Validate

func (r *Redis) Validate() error

Validate 验证 Redis 配置的有效性

func (*Redis) WithAddr

func (r *Redis) WithAddr(addr string) *Redis

WithAddr 设置Redis地址(单实例)

func (*Redis) WithAddrs

func (r *Redis) WithAddrs(addrs []string) *Redis

WithAddrs 设置Redis地址列表(集群模式)

func (*Redis) WithClientName

func (r *Redis) WithClientName(clientName string) *Redis

WithClientName 设置客户端名称

func (*Redis) WithClusterMode

func (r *Redis) WithClusterMode(clusterMode bool) *Redis

WithClusterMode 设置是否集群模式

func (*Redis) WithContextTimeoutEnabled

func (r *Redis) WithContextTimeoutEnabled(enabled bool) *Redis

WithContextTimeoutEnabled 设置是否用 context 控制命令超时

func (*Redis) WithDB

func (r *Redis) WithDB(db int) *Redis

WithDB 设置数据库编号

func (*Redis) WithIdleTimeout

func (r *Redis) WithIdleTimeout(idleTimeout time.Duration) *Redis

WithIdleTimeout 设置空闲超时

func (*Redis) WithMasterName

func (r *Redis) WithMasterName(masterName string) *Redis

WithMasterName 设置哨兵模式 master 名称

func (*Redis) WithMaxActiveConns

func (r *Redis) WithMaxActiveConns(maxActiveConns int) *Redis

WithMaxActiveConns 设置最大活跃连接数

func (*Redis) WithMaxConnAge

func (r *Redis) WithMaxConnAge(maxConnAge time.Duration) *Redis

WithMaxConnAge 设置连接最大存活时间

func (*Redis) WithMaxRedirects

func (r *Redis) WithMaxRedirects(maxRedirects int) *Redis

WithMaxRedirects 设置集群最大重定向次数

func (*Redis) WithMaxRetries

func (r *Redis) WithMaxRetries(maxRetries int) *Redis

WithMaxRetries 设置最大重试次数

func (*Redis) WithMaxRetryBackoff

func (r *Redis) WithMaxRetryBackoff(maxRetryBackoff time.Duration) *Redis

WithMaxRetryBackoff 设置最大重试间隔

func (*Redis) WithMinIdleConns

func (r *Redis) WithMinIdleConns(minIdleConns int) *Redis

WithMinIdleConns 设置最小空闲连接数

func (*Redis) WithMinRetryBackoff

func (r *Redis) WithMinRetryBackoff(minRetryBackoff time.Duration) *Redis

WithMinRetryBackoff 设置最小重试间隔

func (*Redis) WithModuleName

func (r *Redis) WithModuleName(moduleName string) *Redis

WithModuleName 设置模块名称

func (*Redis) WithPassword

func (r *Redis) WithPassword(password string) *Redis

WithPassword 设置密码

func (*Redis) WithPoolSize

func (r *Redis) WithPoolSize(poolSize int) *Redis

WithPoolSize 设置连接池大小

func (*Redis) WithPoolTimeout

func (r *Redis) WithPoolTimeout(poolTimeout time.Duration) *Redis

WithPoolTimeout 设置连接池超时

func (*Redis) WithProtocol

func (r *Redis) WithProtocol(protocol int) *Redis

WithProtocol 设置 RESP 协议版本

func (*Redis) WithReadBufferSize

func (r *Redis) WithReadBufferSize(readBufferSize int) *Redis

WithReadBufferSize 设置读缓冲区大小

func (*Redis) WithReadOnly

func (r *Redis) WithReadOnly(readOnly bool) *Redis

WithReadOnly 设置集群模式只读

func (*Redis) WithReadTimeout

func (r *Redis) WithReadTimeout(readTimeout time.Duration) *Redis

WithReadTimeout 设置读取超时

func (*Redis) WithRouteByLatency

func (r *Redis) WithRouteByLatency(routeByLatency bool) *Redis

WithRouteByLatency 设置集群模式按延迟路由

func (*Redis) WithRouteRandomly

func (r *Redis) WithRouteRandomly(routeRandomly bool) *Redis

WithRouteRandomly 设置集群模式随机路由

func (*Redis) WithSentinelPassword

func (r *Redis) WithSentinelPassword(password string) *Redis

WithSentinelPassword 设置哨兵认证密码

func (*Redis) WithSentinelUsername

func (r *Redis) WithSentinelUsername(username string) *Redis

WithSentinelUsername 设置哨兵认证用户名

func (*Redis) WithUsername

func (r *Redis) WithUsername(username string) *Redis

WithUsername 设置用户名

func (*Redis) WithWriteBufferSize

func (r *Redis) WithWriteBufferSize(writeBufferSize int) *Redis

WithWriteBufferSize 设置写缓冲区大小

func (*Redis) WithWriteTimeout

func (r *Redis) WithWriteTimeout(writeTimeout time.Duration) *Redis

WithWriteTimeout 设置写入超时

type Ristretto

type Ristretto struct {
	ModuleName         string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                           // 模块名
	NumCounters        int64  `mapstructure:"num-counters" yaml:"num-counters" json:"numCounters" validate:"min=1"`       // 计数器数量,用于跟踪访问频率
	MaxCost            int64  `mapstructure:"max-cost" yaml:"max-cost" json:"maxCost" validate:"min=1"`                   // 最大缓存成本
	BufferItems        int64  `mapstructure:"buffer-items" yaml:"buffer-items" json:"bufferItems" validate:"min=1"`       // Get 缓存的大小
	Metrics            bool   `mapstructure:"metrics" yaml:"metrics" json:"metrics"`                                      // 是否启用缓存统计
	IgnoreInternalCost bool   `mapstructure:"ignore-internal-cost" yaml:"ignore-internal-cost" json:"ignoreInternalCost"` // 是否忽略内部成本计算
	KeyToHash          bool   `mapstructure:"key-to-hash" yaml:"key-to-hash" json:"keyToHash"`                            // 是否将键转换为哈希
	Cost               int64  `mapstructure:"cost" yaml:"cost" json:"cost" validate:"min=0"`                              // 每个条目的默认成本
}

Ristretto缓存配置

func DefaultRistretto

func DefaultRistretto() *Ristretto

DefaultRistretto 返回默认 Ristretto 配置的指针,支持链式调用

func DefaultRistrettoConfig

func DefaultRistrettoConfig() Ristretto

DefaultRistrettoConfig 返回默认 Ristretto 配置

func NewRistretto

func NewRistretto(opt *Ristretto) *Ristretto

NewRistretto 创建一个新的 Ristretto 实例

func (*Ristretto) Clone

func (r *Ristretto) Clone() internal.Configurable

Clone 返回 Ristretto 配置的副本

func (*Ristretto) Get

func (r *Ristretto) Get() interface{}

Get 返回 Ristretto 配置的所有字段

func (*Ristretto) GetBufferItems

func (r *Ristretto) GetBufferItems() int64

GetBufferItems 获取缓冲项数量

func (*Ristretto) GetCost

func (r *Ristretto) GetCost() int64

GetCost 获取默认成本

func (*Ristretto) GetMaxCost

func (r *Ristretto) GetMaxCost() int64

GetMaxCost 获取最大成本

func (*Ristretto) GetNumCounters

func (r *Ristretto) GetNumCounters() int64

GetNumCounters 获取计数器数量

func (*Ristretto) IsIgnoreInternalCost

func (r *Ristretto) IsIgnoreInternalCost() bool

IsIgnoreInternalCost 检查是否忽略内部成本

func (*Ristretto) IsKeyToHash

func (r *Ristretto) IsKeyToHash() bool

IsKeyToHash 检查是否将键转换为哈希

func (*Ristretto) IsMetricsEnabled

func (r *Ristretto) IsMetricsEnabled() bool

IsMetricsEnabled 检查是否启用指标

func (*Ristretto) Set

func (r *Ristretto) Set(data interface{})

Set 更新 Ristretto 配置的字段

func (*Ristretto) Validate

func (r *Ristretto) Validate() error

Validate 验证 Ristretto 配置

type Sharded

type Sharded struct {
	ModuleName   string    `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                  // 模块名
	ShardCount   int       `mapstructure:"shard-count" yaml:"shard-count" json:"shardCount" validate:"min=1"` // 分片数量
	BaseType     CacheType `mapstructure:"base-type" yaml:"base-type" json:"baseType"`                        // 基础缓存类型
	HashFunc     string    `mapstructure:"hash-func" yaml:"hash-func" json:"hashFunc"`                        // 哈希函数: fnv, crc32, md5
	LoadBalancer string    `mapstructure:"load-balancer" yaml:"load-balancer" json:"loadBalancer"`            // 负载均衡策略: consistent_hash, round_robin
}

Sharded 分片缓存配置

func DefaultSharded

func DefaultSharded() *Sharded

DefaultSharded 返回默认分片缓存配置的指针,支持链式调用

func DefaultShardedConfig

func DefaultShardedConfig() Sharded

DefaultShardedConfig 返回默认分片缓存配置

func NewSharded

func NewSharded(opt *Sharded) *Sharded

NewSharded 创建一个新的 Sharded 实例

func (*Sharded) Clone

func (s *Sharded) Clone() internal.Configurable

Clone 返回 Sharded 配置的副本

func (*Sharded) Get

func (s *Sharded) Get() interface{}

Get 返回 Sharded 配置的所有字段

func (*Sharded) Set

func (s *Sharded) Set(data interface{})

Set 更新 Sharded 配置的字段

func (*Sharded) Validate

func (s *Sharded) Validate() error

Validate 验证分片缓存配置

type TwoLevel

type TwoLevel struct {
	ModuleName       string        `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                   // 模块名
	L1Type           CacheType     `mapstructure:"l1-type" yaml:"l1-type" json:"l1Type"`                               // L1缓存类型
	L2Type           CacheType     `mapstructure:"l2-type" yaml:"l2-type" json:"l2Type"`                               // L2缓存类型
	L1TTL            time.Duration `mapstructure:"l1-ttl" yaml:"l1-ttl" json:"l1Ttl"`                                  // L1缓存TTL
	L2TTL            time.Duration `mapstructure:"l2-ttl" yaml:"l2-ttl" json:"l2Ttl"`                                  // L2缓存TTL
	SyncStrategy     string        `mapstructure:"sync-strategy" yaml:"sync-strategy" json:"syncStrategy"`             // 同步策略: write_through, write_back, write_around
	L1Size           int           `mapstructure:"l1-size" yaml:"l1-size" json:"l1Size"`                               // L1缓存大小
	L2Size           int           `mapstructure:"l2-size" yaml:"l2-size" json:"l2Size"`                               // L2缓存大小
	PromoteThreshold int           `mapstructure:"promote-threshold" yaml:"promote-threshold" json:"promoteThreshold"` // 提升阈值
}

TwoLevel 二级缓存配置

func DefaultTwoLevel

func DefaultTwoLevel() *TwoLevel

DefaultTwoLevel 返回默认二级缓存配置的指针,支持链式调用

func DefaultTwoLevelConfig

func DefaultTwoLevelConfig() TwoLevel

DefaultTwoLevelConfig 返回默认二级缓存配置

func NewTwoLevel

func NewTwoLevel(opt *TwoLevel) *TwoLevel

NewTwoLevel 创建一个新的 TwoLevel 实例

func (*TwoLevel) Clone

func (t *TwoLevel) Clone() internal.Configurable

Clone 返回 TwoLevel 配置的副本

func (*TwoLevel) Get

func (t *TwoLevel) Get() interface{}

Get 返回 TwoLevel 配置的所有字段

func (*TwoLevel) Set

func (t *TwoLevel) Set(data interface{})

Set 更新 TwoLevel 配置的字段

func (*TwoLevel) Validate

func (t *TwoLevel) Validate() error

Validate 验证二级缓存配置

Jump to

Keyboard shortcuts

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