cache

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingReadThroughGet  = errors.New("cache read-through get function is required")
	ErrMissingReadThroughLoad = errors.New("cache read-through load function is required")
	ErrMissingReadThroughLock = errors.New("cache locked read-through lock function is required")
	ErrLockNotAcquired        = errors.New("cache lock not acquired")
)

Functions

func LockedReadThrough

func LockedReadThrough[T any](ctx context.Context, opts LockedReadThroughOptions[T]) (*T, error)

LockedReadThrough 执行带短租约的缓存读穿透流程。

func ReadThrough

func ReadThrough[T any](ctx context.Context, opts ReadThroughOptions[T]) (*T, error)

ReadThrough 执行缓存 hit -> load -> set 的最小流程。

Types

type BackendKind

type BackendKind string

BackendKind 表示缓存后端类型。

const (
	BackendKindRedis  BackendKind = "redis"
	BackendKindMemory BackendKind = "memory"
)

type DataRole

type DataRole string

DataRole 表示缓存族承载的数据角色。

const (
	DataRoleAuthoritativeState DataRole = "authoritative_state"
	DataRoleMarkerState        DataRole = "marker_state"
	DataRoleRemoteTokenCache   DataRole = "remote_token_cache"
	DataRoleDerivedSnapshot    DataRole = "derived_snapshot"
)

type Family

type Family string

Family 表示 IAM 中一个稳定的缓存族标识。

const (
	FamilyAuthnRefreshToken        Family = "authn.refresh_token"
	FamilyAuthnRevokedAccessToken  Family = "authn.revoked_access_token"
	FamilyAuthnSession             Family = "authn.session"
	FamilyAuthnUserSessionIndex    Family = "authn.user_session_index"
	FamilyAuthnAccountSessionIndex Family = "authn.account_session_index"
	FamilyAuthnLoginOTP            Family = "authn.login_otp"
	FamilyAuthnLoginOTPSendGate    Family = "authn.login_otp_send_gate"
	FamilyIDPWechatAccessToken     Family = "idp.wechat_access_token"
	FamilyIDPWechatSDK             Family = "idp.wechat_sdk"
	FamilyAuthnJWKSPublishSnapshot Family = "authn.jwks_publish_snapshot"
)

type FamilyDescriptor

type FamilyDescriptor struct {
	Family          Family
	Backend         BackendKind
	RedisType       RedisDataType
	Codec           ValueCodecKind
	Role            DataRole
	OwnerModule     string
	KeyPattern      string
	TTLSource       string
	SelectionReason string
	Policy          FamilyPolicy
	Capabilities    []GovernanceCapability
}

FamilyDescriptor 描述一个缓存族的治理元数据。

func Families

func Families() []FamilyDescriptor

Families 返回当前 IAM 缓存目录快照。

func GetFamily

func GetFamily(family Family) (FamilyDescriptor, bool)

GetFamily 返回指定 family 的静态描述。

type FamilyPolicy

type FamilyPolicy struct {
	TTLSource                      string
	WriteMode                      string
	InvalidationMode               string
	HasInternalRefreshCoordination bool
}

FamilyPolicy 描述某个缓存族的静态策略。

type GovernanceCapability

type GovernanceCapability string

GovernanceCapability 表示治理面对 family 暴露的能力。

const (
	GovernanceCapabilityInspect GovernanceCapability = "inspect"
)

type LockedReadThroughOptions

type LockedReadThroughOptions[T any] struct {
	ReadThroughOptions[T]
	Lock          func(context.Context) (ok bool, unlock func(), err error)
	RereadUsable  func(*T) bool
	LockMissError error
}

LockedReadThroughOptions 在 ReadThrough 基础上增加短租约协调。

type ReadThroughOptions

type ReadThroughOptions[T any] struct {
	Get            func(context.Context) (*T, error)
	Valid          func(*T) bool
	Load           func(context.Context) (*T, error)
	TTL            func(*T) time.Duration
	Set            func(context.Context, *T, time.Duration) error
	IgnoreGetError bool
}

ReadThroughOptions 描述一次最小缓存读穿透流程。

type RedisDataType

type RedisDataType string

RedisDataType 表示治理面视角下的 Redis 数据结构。

const (
	RedisDataTypeNone   RedisDataType = "none"
	RedisDataTypeString RedisDataType = "string"
	RedisDataTypeHash   RedisDataType = "hash"
	RedisDataTypeSet    RedisDataType = "set"
	RedisDataTypeZSet   RedisDataType = "zset"
)

type ValueCodecKind

type ValueCodecKind string

ValueCodecKind 表示 family 的 value 编码方式。

const (
	ValueCodecKindMemoryObject ValueCodecKind = "memory_object"
	ValueCodecKindJSON         ValueCodecKind = "json"
	ValueCodecKindMarker       ValueCodecKind = "marker"
	ValueCodecKindString       ValueCodecKind = "string"
	ValueCodecKindLeaseToken   ValueCodecKind = "lease_token"
)

Jump to

Keyboard shortcuts

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