Documentation
¶
Index ¶
- type Entry
- type Stats
- type TTLResponseCache
- func (c *TTLResponseCache) Clear()
- func (c *TTLResponseCache) FindSimilar(model string, body []byte, threshold float64) (Entry, string, bool)
- func (c *TTLResponseCache) Get(key string) (Entry, bool)
- func (c *TTLResponseCache) KeyFor(model string, body []byte) string
- func (c *TTLResponseCache) LoadFromFile(path string) error
- func (c *TTLResponseCache) SaveToFile(path string) error
- func (c *TTLResponseCache) Set(key string, body []byte, header map[string][]string, ttl time.Duration)
- func (c *TTLResponseCache) SetWithRequest(key string, body []byte, header map[string][]string, ttl time.Duration, ...)
- func (c *TTLResponseCache) Size() int
- func (c *TTLResponseCache) Stats() Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Body []byte
Header map[string][]string
ExpiresAt time.Time
// RequestHash stores the SHA256 of the request body so semantic hits can
// compare the request, not just the response (Bifrost-style). Empty = exact key.
RequestHash string
// RequestWords are the significant words of the last user message, used by
// the cheap semantic FindSimilar (Jaccard overlap) without embeddings.
RequestWords []string
// PromptCacheHitTokens approximates deepseek/gemini prompt_cache_hit_tokens.
PromptCacheHitTokens int
PromptCacheMissTokens int
}
type Stats ¶
type Stats struct {
Size int `json:"size"`
MaxSize int `json:"max_size"`
HitRate float64 `json:"hit_rate"`
ExactHits uint64 `json:"exact_hits"`
SimilarHits uint64 `json:"similar_hits"`
Misses uint64 `json:"misses"`
}
Stats captures cache hit/miss counters for the Token Lens widget.
type TTLResponseCache ¶
type TTLResponseCache struct {
// contains filtered or unexported fields
}
func NewTTLResponseCache ¶
func NewTTLResponseCache(maxSize int) *TTLResponseCache
func (*TTLResponseCache) Clear ¶
func (c *TTLResponseCache) Clear()
func (*TTLResponseCache) FindSimilar ¶
func (c *TTLResponseCache) FindSimilar(model string, body []byte, threshold float64) (Entry, string, bool)
FindSimilar returns the most similar cached entry by Jaccard on the request body. threshold 0.8 means 80% word overlap on last user message required. This is a cheap semantic-like cache (Bifrost-style) — no embeddings needed.
func (*TTLResponseCache) KeyFor ¶
func (c *TTLResponseCache) KeyFor(model string, body []byte) string
func (*TTLResponseCache) LoadFromFile ¶
func (c *TTLResponseCache) LoadFromFile(path string) error
LoadFromFile restores cache from disk.
func (*TTLResponseCache) SaveToFile ¶
func (c *TTLResponseCache) SaveToFile(path string) error
SaveToFile persists cache to disk (best-effort, for restart).
func (*TTLResponseCache) Set ¶
func (c *TTLResponseCache) Set(key string, body []byte, header map[string][]string, ttl time.Duration)
Set stores an entry. requestBody is the incoming chat payload (used for semantic RequestHash); pass nil for exact-key-only caches.
func (*TTLResponseCache) SetWithRequest ¶
func (c *TTLResponseCache) SetWithRequest(key string, body []byte, header map[string][]string, ttl time.Duration, requestBody []byte, cacheHit, cacheMiss int)
SetWithRequest stores an entry and keeps the request hash + prompt cache accounting for semantic lookups and DeepSeek-style prompt_cache stats.
func (*TTLResponseCache) Size ¶
func (c *TTLResponseCache) Size() int
func (*TTLResponseCache) Stats ¶
func (c *TTLResponseCache) Stats() Stats