{"modulePath":"github.com/Rethinger/2papi","version":"v0.4.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cache\n\n## Types\n\n```go\ntype Entry struct {\n\tBody      []byte\n\tHeader    map[string][]string\n\tExpiresAt time.Time\n\t// RequestHash stores the SHA256 of the request body so semantic hits can\n\t// compare the request, not just the response (Bifrost-style). Empty = exact key.\n\tRequestHash string\n\t// RequestWords are the significant words of the last user message, used by\n\t// the cheap semantic FindSimilar (Jaccard overlap) without embeddings.\n\tRequestWords []string\n\t// PromptCacheHitTokens approximates deepseek/gemini prompt_cache_hit_tokens.\n\tPromptCacheHitTokens  int\n\tPromptCacheMissTokens int\n}\n```\n\n```go\ntype Stats struct {\n\tSize        int     `json:\"size\"`\n\tMaxSize     int     `json:\"max_size\"`\n\tHitRate     float64 `json:\"hit_rate\"`\n\tExactHits   uint64  `json:\"exact_hits\"`\n\tSimilarHits uint64  `json:\"similar_hits\"`\n\tMisses      uint64  `json:\"misses\"`\n}\n```\nStats captures cache hit/miss counters for the Token Lens widget.\n\n```go\ntype TTLResponseCache struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewTTLResponseCache(maxSize int) *TTLResponseCache\n```\n\n```go\nfunc (c *TTLResponseCache) Clear()\n```\n\n```go\nfunc (c *TTLResponseCache) FindSimilar(model string, body []byte, threshold float64) (Entry, string, bool)\n```\nFindSimilar 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.\n\n```go\nfunc (c *TTLResponseCache) Get(key string) (Entry, bool)\n```\n\n```go\nfunc (c *TTLResponseCache) KeyFor(model string, body []byte) string\n```\n\n```go\nfunc (c *TTLResponseCache) LoadFromFile(path string) error\n```\nLoadFromFile restores cache from disk.\n\n```go\nfunc (c *TTLResponseCache) SaveToFile(path string) error\n```\nSaveToFile persists cache to disk (best-effort, for restart).\n\n```go\nfunc (c *TTLResponseCache) Set(key string, body []byte, header map[string][]string, ttl time.Duration)\n```\nSet stores an entry. requestBody is the incoming chat payload (used for semantic RequestHash); pass nil for exact-key-only caches.\n\n```go\nfunc (c *TTLResponseCache) SetWithRequest(key string, body []byte, header map[string][]string, ttl time.Duration, requestBody []byte, cacheHit, cacheMiss int)\n```\nSetWithRequest stores an entry and keeps the request hash + prompt cache accounting for semantic lookups and DeepSeek-style prompt\\_cache stats.\n\n```go\nfunc (c *TTLResponseCache) Size() int\n```\n\n```go\nfunc (c *TTLResponseCache) Stats() Stats\n```\n\n","path":"github.com/Rethinger/2papi/internal/cache","name":"cache","synopsis":"","isRedistributable":true}
