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

cachetest

package
v0.16.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cachetest 是 data 门面子包:CacheAside 实现契约测试套件(8 场景,含 -race)。

re-export 自 github.com/oekit/pkg/cache/cachetest:类型为泛型 type alias(与源包**完全同一类型**, 双向赋值互通);非泛型函数/变量经 var 引用同一函数值。源包新增导出符号时 本壳需同步(门面跟版税,data 门面化决策已接受)。

Index

Constants

This section is empty.

Variables

View Source
var NewFakeClock = src.NewFakeClock

NewFakeClock 创建起点为 2026-01-01T00:00:00Z 的假时钟。

Functions

func Run

func Run[T any](t *testing.T, c Contract[T], factory func(t *testing.T, source pkgcache.SourceFunc[T]) pkgcache.CacheAside[T])

Run 跑完整契约场景(8 个子测试)。

func RunHitWithClock added in v0.15.0

func RunHitWithClock[T any](t *testing.T, c Contract[T], factory ClockFactory[T])

RunHitWithClock 跑「命中语义」契约(pkg v0.16.0,pkg#25)——实现须提供 cache.HitGetter 能力(GetEx(ctx) (*T, bool, error)),未提供即判失败。

func RunNoBackgroundGoroutine added in v0.15.0

func RunNoBackgroundGoroutine[T any](t *testing.T, factory func(t *testing.T, source pkgcache.SourceFunc[T]) pkgcache.CacheAside[T])

RunNoBackgroundGoroutine 跑「不起后台 goroutine」契约(pkg v0.16.0,pkg#25)—— 构造缓存不得在进程内新增 goroutine。

func RunReadIsolation added in v0.15.0

func RunReadIsolation[T any](t *testing.T, c Contract[T], factory func(t *testing.T, source pkgcache.SourceFunc[T]) pkgcache.CacheAside[T])

RunReadIsolation 跑「读命中返回副本」契约(pkg v0.16.0,pkg#25)——调用方 改写 Get 返回值不得污染缓存内部条目。

func RunReadPromotion added in v0.15.0

func RunReadPromotion[T any](t *testing.T, c Contract[T], capacity int, factory func(t *testing.T, source pkgcache.SourceFunc[T]) pkgcache.CacheAside[T])

RunReadPromotion 跑「读命中提升顺序(LRU)」契约(pkg v0.16.0,pkg#25)—— factory 须构造容量为 capacity 的 LRU 缓存,场景能区分 FIFO 与 LRU。

func RunSweepWithClock added in v0.15.0

func RunSweepWithClock[T any](t *testing.T, c Contract[T], factory ClockFactory[T])

RunSweepWithClock 跑「手动清扫」契约(pkg v0.16.0,pkg#25)——实现须提供 cache.Sweeper 能力(Sweep(ctx) int),未提供即判失败。

func RunWithClock added in v0.11.0

func RunWithClock[T any](t *testing.T, c Contract[T], factory ClockFactory[T])

RunWithClock 跑时钟驱动的 TTL 边界场景(4 子测试:过期闭边界/TTL=0 永不过期/ null marker 过窗重源/重写刷新过期)。

Types

type ClockFactory added in v0.11.0

type ClockFactory[T any] = src.ClockFactory[T]

ClockFactory 是支持时钟注入的缓存工厂形态:实现把 clock.Now 路由到全部 TTL 判定。

type Contract

type Contract[T any] = src.Contract[T]

func Comparable

func Comparable[T comparable]() Contract[T]

Comparable 返回可比较类型的现成 Contract。

type FakeClock added in v0.11.0

type FakeClock = src.FakeClock

FakeClock 是套件提供的假时钟(并发安全;测试内手动推进)——供时钟注入实现 接入 RunWithClock 假时钟 TTL 套件(pkg v0.13.0)。

Jump to

Keyboard shortcuts

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