cache

package
v0.1.7-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package cache manages downloaded files and their metadata.

Index

Constants

View Source
const MetadataFilename = ".metadata.json"

MetadataFilename is the name of the metadata file for each cache entry.

Variables

View Source
var (
	// ErrCacheMiss is returned when a requested cache entry does not exist.
	ErrCacheMiss = errors.New("cache miss")

	// ErrChecksumMismatch indicates a checksum verification failure.
	ErrChecksumMismatch = errors.New("checksum mismatch")

	// ErrInvalidInput indicates invalid input to a cache operation.
	ErrInvalidInput = errors.New("invalid input")

	// ErrAuthExpired indicates the authentication token has expired.
	ErrAuthExpired = errors.New("authentication expired")

	// ErrDownloadFailed indicates a download operation failed.
	ErrDownloadFailed = errors.New("download failed")
)

Functions

func CalculateChecksum

func CalculateChecksum(filePath string) (string, error)

CalculateChecksum computes a file's SHA-256 checksum.

Types

type DownloadOptions

type DownloadOptions struct {
	LicenseKey       string
	DownloadID       string // e.g., "xenforo", "xfmg"
	Version          string
	URL              string
	ExpectedChecksum string // SHA-256, optional
	ExpectedSize     int64  // 0 = unknown
	Filename         string // overrides Content-Disposition
	SkipCacheCheck   bool
}

DownloadOptions specifies download parameters.

type DownloadResult

type DownloadResult struct {
	Entry           *Entry
	WasCached       bool
	BytesDownloaded int64
}

DownloadResult contains information about a completed download.

type Entry

type Entry struct {
	LicenseKey   string
	Metadata     EntryMetadata
	FilePath     string
	MetadataPath string
}

Entry represents a cached download file.

type EntryMetadata

type EntryMetadata struct {
	DownloadID   string    `json:"download_id"`
	Version      string    `json:"version"`
	Filename     string    `json:"filename"`
	Checksum     string    `json:"checksum"`
	Size         int64     `json:"size"`
	DownloadedAt time.Time `json:"downloaded_at"`
	SourceURL    string    `json:"source_url,omitempty"`
}

EntryMetadata holds information about a cached file.

type Manager

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

Manager manages cache storage on disk.

func NewManager

func NewManager() (*Manager, error)

NewManager creates a new cache manager.

func (*Manager) BasePath

func (m *Manager) BasePath() string

BasePath returns the cache manager's base directory.

func (*Manager) Delete

func (m *Manager) Delete(licenseKey string, downloadID, version string) error

Delete removes a cache entry.

func (*Manager) Download

func (m *Manager) Download(ctx context.Context, opts DownloadOptions, progress ProgressCallback) (*DownloadResult, error)

Download downloads and caches a file without authentication.

func (*Manager) DownloadWithAuth

func (m *Manager) DownloadWithAuth(ctx context.Context, opts DownloadOptions, authToken string, progress ProgressCallback) (*DownloadResult, error)

DownloadWithAuth downloads and caches a file with an authentication token.

func (*Manager) EntryPath

func (m *Manager) EntryPath(licenseKey string, downloadID, version string) (string, error)

EntryPath returns the directory path for a cache entry.

func (*Manager) GetEntry

func (m *Manager) GetEntry(licenseKey string, downloadID, version string) (*Entry, error)

GetEntry retrieves a cache entry by license, download ID, and version.

func (*Manager) List

func (m *Manager) List() ([]*Entry, error)

List returns all cached entries.

func (*Manager) ListForLicense

func (m *Manager) ListForLicense(licenseKey string) ([]*Entry, error)

ListForLicense returns all cached entries for a specific license.

func (*Manager) PurgeAll

func (m *Manager) PurgeAll() error

PurgeAll removes all cached files.

func (*Manager) PurgeLicense

func (m *Manager) PurgeLicense(licenseKey string) error

PurgeLicense removes all cached files for a specific license.

func (*Manager) SaveMetadata

func (m *Manager) SaveMetadata(licenseKey string, metadata *EntryMetadata) error

SaveMetadata saves cache entry metadata to disk.

func (*Manager) TotalSize

func (m *Manager) TotalSize() (int64, error)

TotalSize returns the total size of all cached files in bytes.

func (*Manager) Verify

func (m *Manager) Verify(entry *Entry) (bool, error)

Verify checks if a cached file's checksum is valid.

type ProgressCallback

type ProgressCallback func(current, total int64)

ProgressCallback reports download progress; total is -1 if unknown.

Jump to

Keyboard shortcuts

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