cache

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package cache provides a generic in-memory list cache with TTL-based invalidation, designed to protect loaders from repeated expensive disk scans within a single agent turn.

Usage:

var c cache.List[MyItem]

// In List():
return c.Get(func() []MyItem { return expensiveScan() })

// In ForceSync():
c.Invalidate()

Index

Constants

View Source
const DefaultTTL = 5 * time.Second

DefaultTTL is the default duration cached results remain valid. Chosen to be short enough for interactive responsiveness (a single agent turn completes well under 5 s) while eliminating redundant disk walks when multiple tools are called in quick succession.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List[T any] struct {
	TTL time.Duration // 0 means DefaultTTL
	// contains filtered or unexported fields
}

List is a thread-safe in-memory cache for a slice of items. The zero value is ready to use with DefaultTTL.

func (*List[T]) Get

func (c *List[T]) Get(fill func() []T) []T

Get returns cached items if still fresh, otherwise calls fill to populate the cache. Thread-safe; concurrent callers collapse to a single fill call.

func (*List[T]) Invalidate

func (c *List[T]) Invalidate()

Invalidate marks the cache as stale. The next Get call will re-populate.

Jump to

Keyboard shortcuts

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