cache

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// AntigravityReasoningReplayCacheTTL limits how long encrypted reasoning replay
	// items stay in process memory.
	AntigravityReasoningReplayCacheTTL = 1 * time.Hour

	// AntigravityReasoningReplayCacheMaxEntries bounds process memory for replay
	// continuity. Oldest entries are evicted first.
	AntigravityReasoningReplayCacheMaxEntries = 10240

	// AntigravityReasoningReplayCacheEvictBatchSize leaves headroom after the cache
	// reaches capacity so high write volume does not rescan the map every turn.
	AntigravityReasoningReplayCacheEvictBatchSize = 128

	// AntigravityReasoningReplayCacheMaxItemsPerEntry and MaxBytesPerEntry
	// bound one logical conversation. Oversized chains are not partially cached,
	// because dropping an arbitrary prefix would break native signature ordering.
	AntigravityReasoningReplayCacheMaxItemsPerEntry = 4096
	AntigravityReasoningReplayCacheMaxBytesPerEntry = 16 << 20
)
View Source
const (
	// KimiThinkingReplayCacheTTL limits how long signed assistant content stays replayable.
	KimiThinkingReplayCacheTTL = 1 * time.Hour

	// KimiThinkingReplayCacheMaxEntries bounds process memory used for replay continuity.
	KimiThinkingReplayCacheMaxEntries = 10240

	// KimiThinkingReplayCacheEvictBatchSize leaves headroom after reaching capacity.
	KimiThinkingReplayCacheEvictBatchSize = 128

	// KimiThinkingReplayCacheMaxBytesPerEntry bounds one complete assistant content array.
	KimiThinkingReplayCacheMaxBytesPerEntry = 8 << 20

	// KimiThinkingReplayCacheMaxBlocksPerEntry prevents pathological content arrays.
	KimiThinkingReplayCacheMaxBlocksPerEntry = 512

	// KimiThinkingReplayCacheMaxTotalBytes bounds aggregate in-process replay content.
	KimiThinkingReplayCacheMaxTotalBytes = 256 << 20
)
View Source
const (
	// SignatureCacheTTL is how long signatures are valid
	SignatureCacheTTL = 3 * time.Hour

	// SignatureTextHashLen is the length of the hash key (16 hex chars = 64-bit key space)
	SignatureTextHashLen = 16

	// MinValidSignatureLen is the minimum length for a signature to be considered valid
	MinValidSignatureLen = 50

	// CacheCleanupInterval controls how often stale entries are purged
	CacheCleanupInterval = 10 * time.Minute
)

Variables

This section is empty.

Functions

func CacheAntigravityReasoningReplayItem added in v0.0.22

func CacheAntigravityReasoningReplayItem(modelName, sessionKey string, item []byte) bool

CacheAntigravityReasoningReplayItem stores a final GPT/Codex reasoning item for stateless replay. The stored item is normalized to the minimal shape accepted by Responses input replay.

func CacheAntigravityReasoningReplayItems added in v0.0.22

func CacheAntigravityReasoningReplayItems(modelName, sessionKey string, items [][]byte) bool

CacheAntigravityReasoningReplayItems stores the final GPT/Codex assistant output items needed to replay a stateless next turn.

func CacheAntigravityReasoningReplayItemsBestEffort added in v0.0.22

func CacheAntigravityReasoningReplayItemsBestEffort(ctx context.Context, modelName, sessionKey string, items [][]byte) bool

CacheAntigravityReasoningReplayItemsBestEffort stores replay items for completed response paths.

func CacheKimiThinkingReplayBestEffort added in v0.0.23

func CacheKimiThinkingReplayBestEffort(ctx context.Context, modelFamily, sessionKey string, content []byte) bool

CacheKimiThinkingReplayBestEffort stores one complete signed assistant content array.

func CacheSignature

func CacheSignature(modelName, text, signature string)

CacheSignature stores a thinking signature for a given model group and text. Used for Claude models that require signed thinking blocks in multi-turn conversations.

func ClearAntigravityReasoningReplayCache added in v0.0.22

func ClearAntigravityReasoningReplayCache()

ClearAntigravityReasoningReplayCache clears all Antigravity reasoning replay state.

func ClearKimiThinkingReplayCache added in v0.0.23

func ClearKimiThinkingReplayCache()

ClearKimiThinkingReplayCache clears all in-process Kimi replay state.

func ClearSignatureCache

func ClearSignatureCache(modelName string)

ClearSignatureCache clears signature cache for a specific model group or all groups.

func DeleteAntigravityReasoningReplayItem added in v0.0.22

func DeleteAntigravityReasoningReplayItem(modelName, sessionKey string)

DeleteAntigravityReasoningReplayItem removes one replay item after upstream rejects it or the caller otherwise knows it is stale.

func DeleteAntigravityReasoningReplayItemRequired added in v0.0.22

func DeleteAntigravityReasoningReplayItemRequired(ctx context.Context, modelName, sessionKey string) error

DeleteAntigravityReasoningReplayItemRequired removes one replay item for request-time paths.

func DeleteAntigravityReasoningReplayItemsIfUnchanged added in v0.0.22

func DeleteAntigravityReasoningReplayItemsIfUnchanged(ctx context.Context, modelName, sessionKey string, snapshot AntigravityReasoningReplaySnapshot) (bool, error)

DeleteAntigravityReasoningReplayItemsIfUnchanged clears replay state only when it still matches the state read for this request.

func DeleteKimiThinkingReplayIfUnchanged added in v0.0.23

func DeleteKimiThinkingReplayIfUnchanged(ctx context.Context, modelFamily, sessionKey string, snapshot KimiThinkingReplaySnapshot) (bool, error)

DeleteKimiThinkingReplayIfUnchanged clears replay state only if the request snapshot is current.

func DeleteKimiThinkingReplayRequired added in v0.0.23

func DeleteKimiThinkingReplayRequired(ctx context.Context, modelFamily, sessionKey string) error

DeleteKimiThinkingReplayRequired removes stale replay state unconditionally.

func GetAntigravityReasoningReplayItem added in v0.0.22

func GetAntigravityReasoningReplayItem(modelName, sessionKey string) ([]byte, bool)

GetAntigravityReasoningReplayItem retrieves a normalized reasoning replay item.

func GetAntigravityReasoningReplayItems added in v0.0.22

func GetAntigravityReasoningReplayItems(modelName, sessionKey string) ([][]byte, bool)

GetAntigravityReasoningReplayItems retrieves normalized assistant output items.

func GetAntigravityReasoningReplayItemsRequired added in v0.0.22

func GetAntigravityReasoningReplayItemsRequired(ctx context.Context, modelName, sessionKey string) ([][]byte, bool, error)

GetAntigravityReasoningReplayItemsRequired retrieves replay items for request-time paths.

func GetCachedSignature

func GetCachedSignature(modelName, text string) string

GetCachedSignature retrieves a cached signature for a given model group and text. Returns empty string if not found or expired.

func GetKimiThinkingReplayRequired added in v0.0.23

func GetKimiThinkingReplayRequired(ctx context.Context, modelFamily, sessionKey string) ([]byte, bool, error)

GetKimiThinkingReplayRequired retrieves complete assistant content for request-time replay.

func GetModelGroup

func GetModelGroup(modelName string) string

func HasValidSignature

func HasValidSignature(modelName, signature string) bool

HasValidSignature checks if a signature is valid (non-empty and long enough)

func ReplaceAntigravityReasoningReplayItemsIfUnchanged added in v0.0.22

func ReplaceAntigravityReasoningReplayItemsIfUnchanged(ctx context.Context, modelName, sessionKey string, snapshot AntigravityReasoningReplaySnapshot, items [][]byte) (bool, error)

ReplaceAntigravityReasoningReplayItemsIfUnchanged publishes a completed chain only when no newer request has changed the state read by this request.

func ReplaceKimiThinkingReplayIfUnchanged added in v0.0.23

func ReplaceKimiThinkingReplayIfUnchanged(ctx context.Context, modelFamily, sessionKey string, snapshot KimiThinkingReplaySnapshot, content []byte) (bool, error)

ReplaceKimiThinkingReplayIfUnchanged stores completed content only if the request snapshot is current.

func SetSignatureBypassStrictMode

func SetSignatureBypassStrictMode(strict bool)

SetSignatureBypassStrictMode controls whether bypass mode uses strict protobuf-tree validation.

func SetSignatureCacheEnabled

func SetSignatureCacheEnabled(enabled bool)

SetSignatureCacheEnabled switches Antigravity signature handling between cache mode and bypass mode.

func SignatureBypassStrictMode

func SignatureBypassStrictMode() bool

SignatureBypassStrictMode returns whether bypass mode uses strict protobuf-tree validation.

func SignatureCacheEnabled

func SignatureCacheEnabled() bool

SignatureCacheEnabled returns whether signature cache validation is enabled.

Types

type AntigravityReasoningReplaySnapshot added in v0.0.22

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

AntigravityReasoningReplaySnapshot identifies the exact replay state read for one request. Its fields are intentionally opaque outside this package.

func GetAntigravityReasoningReplayItemsWithSnapshotRequired added in v0.0.22

func GetAntigravityReasoningReplayItemsWithSnapshotRequired(ctx context.Context, modelName, sessionKey string) ([][]byte, AntigravityReasoningReplaySnapshot, bool, error)

GetAntigravityReasoningReplayItemsWithSnapshotRequired retrieves replay items and the exact cache state that guarded this request.

type KimiThinkingReplaySnapshot added in v0.0.23

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

KimiThinkingReplaySnapshot identifies the exact replay generation read for one request.

func GetKimiThinkingReplayWithSnapshotRequired added in v0.0.23

func GetKimiThinkingReplayWithSnapshotRequired(ctx context.Context, modelFamily, sessionKey string) ([]byte, KimiThinkingReplaySnapshot, bool, error)

GetKimiThinkingReplayWithSnapshotRequired retrieves replay content and the exact cache state read.

type SignatureEntry

type SignatureEntry struct {
	Signature string
	Timestamp time.Time
}

SignatureEntry holds a cached thinking signature with timestamp

Jump to

Keyboard shortcuts

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