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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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