Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package cache 进程内检查缓存原语(stdlib-only):TTL 缓存 + 刷新进行中 并发合并(inflight singleflight)+ 失败短 TTL。收编自消费方健康检查器的 双份手写形态——/health 轮询会放大昂贵的 refresh(子进程 fan-out/远程探测), 无合并则 N 个观察者并发拉起 N 轮全量刷新。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

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

Checker 缓存一次错误型检查的结果:成功缓存 ttl,失败缓存 failTTL(失败多为 瞬时,恢复后不该被旧失败多压一整个正常周期);刷新进行中后来者合并等待同一 次刷新(ctx 感知,不叠加刷新轮次)。并发安全。

func NewChecker

func NewChecker(refresh func(ctx context.Context) error, ttl, failTTL time.Duration, opts ...Option) *Checker

NewChecker 构造;failTTL<=0 时与 ttl 同值。

func (*Checker) Check

func (c *Checker) Check(ctx context.Context) error

Check 返回缓存有效期内的结果;过期则触发一次刷新(并发调用合并为一次)。

type Option

type Option func(*Checker)

Option Checker 可选项。

func WithClock

func WithClock(now func() time.Time) Option

WithClock 注入时钟(测试用;缺省 time.Now)。

Jump to

Keyboard shortcuts

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