cached

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 4 Imported by: 0

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

func New(inner provider.Provider, c *cache.Cache) *Provider

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

func (p *Provider) DefaultModel() string

DefaultModel delegates to the inner provider.

func (*Provider) Name

func (p *Provider) Name() string

Name delegates to the inner provider.

Jump to

Keyboard shortcuts

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