cache

package
v1.21.21 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCacheDisabled indicates caching is disabled
	ErrCacheDisabled = errors.New("caching is disabled")
	// ErrNotFound indicates the entry was not found in cache
	ErrNotFound = errors.New("cache entry not found")
)

Functions

This section is empty.

Types

type Cache

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

Cache manages AI response caching in SQLite

func New

func New(config Config) (*Cache, error)

New creates a new cache instance

func (*Cache) Clear

func (c *Cache) Clear(projectName string) error

Clear removes all cache entries

func (*Cache) Close

func (c *Cache) Close() error

Close closes the database connection

func (*Cache) ExportToJSON

func (c *Cache) ExportToJSON(w io.Writer, projectName string) error

ExportToJSON exports cache entries to JSON

func (*Cache) Get

func (c *Cache) Get(prompt, model string, temperature float64, maxTokens int) (*Entry, error)

Get retrieves a cached response

func (*Cache) GetHistory

func (c *Cache) GetHistory(limit int, projectName string) ([]Entry, error)

GetHistory retrieves recent AI interactions

func (*Cache) GetStats

func (c *Cache) GetStats(projectName string) ([]StatsEntry, error)

GetStats retrieves aggregated statistics

func (*Cache) ImportFromJSON

func (c *Cache) ImportFromJSON(r io.Reader) error

ImportFromJSON imports cache entries from JSON

func (*Cache) Set

func (c *Cache) Set(entry *Entry) error

Set stores a response in the cache

type Config

type Config struct {
	DBPath  string        // Database file path (default: ~/.cache/clicky-ai.db)
	TTL     time.Duration // Cache time-to-live
	NoCache bool          // Disable caching
	Debug   bool          // Enable debug output
}

Config holds cache configuration

type Entry

type Entry struct {
	// Pointer (8 bytes)
	ExpiresAt *time.Time

	// Strings (16 bytes each on 64-bit)
	CacheKey    string
	PromptHash  string
	Model       string
	Prompt      string
	Response    string
	Error       string
	ProjectName string
	TaskName    string
	SessionID   string

	// 8-byte types
	ID          int64
	DurationMS  int64
	CostUSD     float64
	Temperature float64
	CreatedAt   time.Time
	AccessedAt  time.Time

	// 4-byte types
	TokensInput      int
	TokensOutput     int
	TokensCacheRead  int
	TokensCacheWrite int
	TokensTotal      int
	MaxTokens        int
}

Entry represents a cached AI response

type StatsEntry

type StatsEntry struct {
	// Strings (16 bytes each)
	Model       string
	ProjectName string

	// 8-byte types
	TotalRequests      int64
	SuccessfulRequests int64
	FailedRequests     int64
	TotalTokens        int64
	AvgDurationMS      int64
	TotalCost          float64
	FirstRequest       time.Time
	LastRequest        time.Time
}

StatsEntry represents aggregated statistics

Jump to

Keyboard shortcuts

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