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 ¶
- Variables
- func IsNotFound(err error) bool
- type Config
- type Entry
- type Manager
- func (m *Manager) Clear(ctx context.Context) error
- func (m *Manager) Delete(ctx context.Context, key string) error
- func (m *Manager) DiskStats() (bytes, entries int64, err error)
- func (m *Manager) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (m *Manager) Has(ctx context.Context, key string) bool
- func (m *Manager) Limits() (maxSizeBytes, maxEntries int64)
- func (m *Manager) Stats() Stats
- func (m *Manager) Store(ctx context.Context, key string, reader io.Reader) (string, error)
- type Stats
Constants ¶
This section is empty.
Variables ¶
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") // ErrCacheEntryNotFound means the entry is not currently in the cache. It // covers both an entry absent from the in-memory index (never stored, or // evicted) and one whose backing file has gone from disk. Callers use // IsNotFound to tell an evicted entry from a genuine I/O error. ErrCacheEntryNotFound = errors.New("cache entry not found") 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 ¶
func IsNotFound ¶ added in v1.28.2
IsNotFound reports whether err indicates the cache entry is not currently retrievable (never stored, evicted, or its file is gone from disk), as opposed to a genuine I/O error.
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 (*Manager) DiskStats ¶ added in v1.25.0
DiskStats returns the current on-disk cache size in bytes and the number of cached packfiles, by walking the cache directory.
func (*Manager) Get ¶
Get retrieves a cached packfile by key Returns a ReadCloser for the packfile, or nil if not found.