cache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SchemaVersion is incremented when the cache format changes.
	// Bumped to 3: added staleness detection fields (BaseDirModTimes, FileSample, TotalFileCount).
	SchemaVersion = 3
)

Variables

This section is empty.

Functions

func ExpandBaseDirs

func ExpandBaseDirs(baseDirs []string) []string

ExpandBaseDirs normalizes base directory paths by expanding ~, $HOME, %USERPROFILE%

func GetCacheDir

func GetCacheDir() (string, error)

GetCacheDir returns the platform-specific cache directory for bagel

Types

type CachedFileIndex

type CachedFileIndex struct {
	Metadata Metadata            `json:"metadata"`
	Entries  map[string][]string `json:"entries"` // pattern name -> file paths
}

CachedFileIndex represents the serializable form of a file index

type FileSampleEntry

type FileSampleEntry struct {
	Path    string `json:"path"`
	ModTime int64  `json:"mod_time"` // Unix nanoseconds
	Size    int64  `json:"size"`
}

FileSampleEntry represents a sampled file for staleness validation

type LoadInput

type LoadInput struct {
	BaseDirs       []string
	Patterns       []fileindex.Pattern
	MaxDepth       int
	FollowSymlinks bool
	TTL            time.Duration // Cache expiration duration (0 = no TTL check)
	ValidateFiles  bool          // Enable file sample validation
}

LoadInput holds the parameters for loading a cached file index

type Metadata

type Metadata struct {
	SchemaVersion  int       `json:"schema_version"`
	CreatedAt      time.Time `json:"created_at"`
	BaseDirs       []string  `json:"base_dirs"` // Stored as expanded paths
	PatternsHash   string    `json:"patterns_hash"`
	MaxDepth       int       `json:"max_depth"`
	FollowSymlinks bool      `json:"follow_symlinks"`

	// Staleness detection fields
	BaseDirModTimes map[string]int64  `json:"base_dir_mod_times"` // dir -> mtime (Unix nanoseconds)
	FileSample      []FileSampleEntry `json:"file_sample"`        // Sampled files for validation
	TotalFileCount  int               `json:"total_file_count"`
}

Metadata holds information about the cached file index

type SaveInput

type SaveInput struct {
	BaseDirs       []string
	Patterns       []fileindex.Pattern
	MaxDepth       int
	FollowSymlinks bool
	Index          *fileindex.FileIndex
	SampleSize     int // Number of files to sample for staleness detection
}

SaveInput holds the parameters for saving a file index to cache

type StalenessCheckInput

type StalenessCheckInput struct {
	Metadata      Metadata
	TTL           time.Duration
	ValidateFiles bool
}

StalenessCheckInput holds parameters for checking cache staleness

type StalenessResult

type StalenessResult struct {
	IsStale bool
	Reason  string // "ttl_expired", "base_dir_changed", "file_missing", "file_modified"
	Details string
}

StalenessResult represents the result of a staleness check

type Store

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

Store manages file index caching

func NewStore

func NewStore() (*Store, error)

NewStore creates a new cache store with the default cache directory

func (*Store) Clear

func (s *Store) Clear() error

Clear removes all cache files in the cache directory. Subdirectories are skipped intentionally - this function only cleans files created by this cache package (fileindex-*.json).

func (*Store) Load

func (s *Store) Load(ctx context.Context, input LoadInput) (*fileindex.FileIndex, error)

Load attempts to load a cached file index Returns nil if the cache doesn't exist or is invalid

func (*Store) Save

func (s *Store) Save(ctx context.Context, input SaveInput) error

Save persists a file index to cache

Jump to

Keyboard shortcuts

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