cache

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cache provides file-based caching with TTL and version support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashFile

func HashFile(path string) (string, error)

HashFile computes SHA256 hash of a file for cache invalidation.

Types

type Manager

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

Manager provides thread-safe file-based caching with TTL and version support.

func NewManager

func NewManager(opts Options) *Manager

NewManager creates a new cache manager.

func (*Manager) Clear

func (m *Manager) Clear() error

Clear removes all cache entries in the cache directory.

func (*Manager) Get

func (m *Manager) Get(key string, target interface{}) (bool, error)

Get loads a cached value by key. Returns true if cache is valid. target must be a pointer to the type to unmarshal into.

func (*Manager) GetStats

func (m *Manager) GetStats() Stats

GetStats returns cache hit/miss statistics.

func (*Manager) Invalidate

func (m *Manager) Invalidate(key string) error

Invalidate removes a specific cache entry.

func (*Manager) Set

func (m *Manager) Set(key string, data interface{}) error

Set stores a value in the cache.

type Options

type Options struct {
	Dir     string        // Directory to store cache files
	TTL     time.Duration // Time-to-live for cache entries
	Version string        // Cache version (entries with different version are invalidated)
}

Options configures a cache Manager.

type Stats

type Stats struct {
	Hits   int
	Misses int
	Errors int
}

Stats tracks cache hit/miss statistics.

Jump to

Keyboard shortcuts

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