Documentation
¶
Overview ¶
Package cached provides a CachedProvider decorator that wraps any Provider and transparently caches responses to avoid redundant identical API calls.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider wraps an inner provider and caches Complete responses. When OnToken streaming is requested, caching is skipped (streaming responses are not suitable for replay).
func New ¶
New wraps inner with response caching using the provided cache.
inner is re-wrapped in provider.WithPanicSafety as a defense in depth: callers that obtain providers via provider.Build are already safe, but a future caller that builds a raw provider and passes it here would lose the safety net. WithPanicSafety is idempotent so this is harmless when inner is already wrapped.
func (*Provider) Complete ¶
func (p *Provider) Complete(ctx context.Context, prompt string, opts provider.Options) (*provider.Result, error)
Complete checks the cache first. On a hit the cached response is returned immediately. On a miss the inner provider is called and the result stored. Streaming requests (OnToken != nil) bypass the cache entirely.
func (*Provider) DefaultModel ¶
DefaultModel delegates to the inner provider.