cache

package
v3.3.285 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const EntryMetadataVersion = 2

Variables

View Source
var (
	ErrInvalidByteRange       = errors.New("invalid byte range")
	ErrSparseFilesUnsupported = errors.New("sparse files are not supported by the cache volume")
)
View Source
var ErrInvalidEntryMetadata = errors.New("invalid cache entry metadata")

Functions

func ByteRangeCovered added in v3.3.285

func ByteRangeCovered(ranges []ByteRange, requested ByteRange) (bool, error)

ByteRangeCovered reports whether ranges completely cover requested.

func ByteRangesCoverFile added in v3.3.285

func ByteRangesCoverFile(ranges []ByteRange, fileSize int64) (bool, error)

ByteRangesCoverFile reports whether ranges cover every byte in a file.

Types

type ByteRange added in v3.3.285

type ByteRange struct {
	Start int64 `json:"start"`
	End   int64 `json:"end"`
}

ByteRange identifies a half-open range of bytes: [Start, End).

func MissingByteRanges added in v3.3.285

func MissingByteRanges(ranges []ByteRange, requested ByteRange) ([]ByteRange, error)

MissingByteRanges returns the parts of requested that ranges do not cover.

func NormalizeByteRanges added in v3.3.285

func NormalizeByteRanges(ranges []ByteRange) ([]ByteRange, error)

NormalizeByteRanges sorts ranges and merges ranges that overlap or touch. Empty ranges are omitted. The input slice is not modified.

func (ByteRange) Validate added in v3.3.285

func (r ByteRange) Validate() error

Validate checks that the range has non-negative, ordered offsets.

type EntryMetadata added in v3.3.109

type EntryMetadata struct {
	Version int         `json:"version"`
	Path    string      `json:"path"`
	Size    int64       `json:"size"`
	ModTime time.Time   `json:"mtime"`
	ETag    string      `json:"etag,omitempty"`
	Ranges  []ByteRange `json:"ranges"`
}

EntryMetadata identifies cached ranges for a specific remote file version.

func NewEntryMetadata added in v3.3.109

func NewEntryMetadata(path string, size int64, modTime time.Time) EntryMetadata

func (EntryMetadata) CachedByteCount added in v3.3.285

func (m EntryMetadata) CachedByteCount() (int64, error)

CachedByteCount returns the number of valid bytes represented by the ranges.

func (EntryMetadata) IsComplete added in v3.3.285

func (m EntryMetadata) IsComplete() bool

IsComplete reports whether the valid ranges cover the complete file.

func (EntryMetadata) Matches added in v3.3.109

func (m EntryMetadata) Matches(other EntryMetadata) bool

Matches compares the listing identity. HTTP validators are checked separately because callers looking up cached bytes have only listing metadata.

func (EntryMetadata) SameContent added in v3.3.285

func (m EntryMetadata) SameContent(other EntryMetadata) bool

SameContent also requires the HTTP validator to match before merging bytes.

func (EntryMetadata) Validate added in v3.3.285

func (m EntryMetadata) Validate() error

Validate checks the schema version, file size, and normalized range list.

func (EntryMetadata) WithCompleteRange added in v3.3.285

func (m EntryMetadata) WithCompleteRange() (EntryMetadata, error)

WithCompleteRange returns metadata covering the complete file.

func (EntryMetadata) WithRanges added in v3.3.285

func (m EntryMetadata) WithRanges(ranges []ByteRange) (EntryMetadata, error)

WithRanges returns metadata with a validated, normalized range list.

type Stats

type Stats struct {
	CapacityBytes          int64
	CapacityBytesRemaining int64
	MaxFileCount           int64
	FileCountRemaining     int64
	FileCount              atomic.Int64
	ReadBytes              atomic.Int64
	ReadCount              atomic.Int64
	SizeBytes              atomic.Int64
	WriteBytes             atomic.Int64
	WriteCount             atomic.Int64
	LoadDuration           time.Duration
	LruCount               int
	PinnedCount            int
	PinnedPaths            map[string]int
	LruKeys                []string
}

Stats maintains statistics about cache usage. In non-debug builds, this type exists but has no methods for retrieving statistics.

func (*Stats) ResetCounters

func (st *Stats) ResetCounters()

ResetCounters sets "counter" type stats to zero.

Directories

Path Synopsis
Package disk implements a disk-based cache for file data.
Package disk implements a disk-based cache for file data.

Jump to

Keyboard shortcuts

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