cache

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package cache provides disk-based caching for Git packfiles with in-memory metadata.

The cache manager stores packfiles on disk and uses Ristretto for in-memory metadata caching. It supports size-based eviction, concurrent access, and provides statistics about cache usage.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToCreateCacheDirectory = errors.New("failed to create cache directory")
	ErrFailedToCreateRistrettoCache = errors.New("failed to create ristretto cache")
	ErrFailedToCalculateDiskUsage   = errors.New("failed to calculate disk usage")
	ErrCachedFileNotFound           = errors.New("cached file not found")
	ErrFailedToCreateCacheFile      = errors.New("failed to create cache file")
	ErrFailedToWriteCacheFile       = errors.New("failed to write cache file")
	ErrFailedToRenameCacheFile      = errors.New("failed to rename cache file")
	ErrFailedToRemoveCacheFile      = errors.New("failed to remove cache file")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// CacheDir is the directory to store packfiles
	CacheDir string
	// MaxSizeBytes is the maximum cache size in bytes
	MaxSizeBytes int64
	// MaxEntries is the maximum number of entries to keep in memory
	MaxEntries int64
}

Config holds configuration for the cache manager.

type Entry

type Entry struct {
	// Key is the cache key
	Key string
	// FilePath is the path to the cached packfile on disk
	FilePath string
	// Size is the size of the packfile in bytes
	Size int64
	// CreatedAt is when the entry was created
	CreatedAt time.Time
	// LastAccessed is when the entry was last accessed
	LastAccessed time.Time
}

Entry represents metadata about a cached packfile.

type Manager

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

Manager handles caching of Git packfiles.

func New

func New(cfg Config) (*Manager, error)

New creates a new cache manager.

func (*Manager) Clear

func (m *Manager) Clear(ctx context.Context) error

Clear removes all cached entries.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, key string) error

Delete removes a cached entry.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, key string) (io.ReadCloser, error)

Get retrieves a cached packfile by key Returns a ReadCloser for the packfile, or nil if not found.

func (*Manager) Has

func (m *Manager) Has(ctx context.Context, key string) bool

Has checks if a key exists in the cache.

func (*Manager) Stats

func (m *Manager) Stats() Stats

Stats returns cache statistics.

func (*Manager) Store

func (m *Manager) Store(ctx context.Context, key string, reader io.Reader) (string, error)

Store saves a packfile to disk and caches its metadata The reader will be fully consumed and the packfile stored to disk.

type Stats

type Stats struct {
	CurrentSize  int64
	MaxSize      int64
	UsagePercent float64
}

Stats represents cache statistics.

Jump to

Keyboard shortcuts

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