cache

package
v0.5.0-beta Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache provides file system cache management for image and video files.

Index

Constants

This section is empty.

Variables

View Source
var ErrFileTooLarge = errors.New("file size exceeds cache limit")

ErrFileTooLarge is returned when a single file exceeds the cache limit.

Functions

This section is empty.

Types

type BatchResult

type BatchResult struct {
	Success int `json:"success"`
	Failed  int `json:"failed"`
}

BatchResult holds results of batch delete.

type ClearResult

type ClearResult struct {
	Deleted int     `json:"deleted"`
	FreedMB float64 `json:"freed_mb"`
}

ClearResult holds results of cache clear.

type FileInfo

type FileInfo struct {
	Name      string `json:"name"`
	SizeBytes int64  `json:"size_bytes"`
	ModTimeMs int64  `json:"mod_time_ms"`
}

FileInfo holds metadata for a single cached file.

type FileListResult

type FileListResult struct {
	Total    int        `json:"total"`
	Page     int        `json:"page"`
	PageSize int        `json:"page_size"`
	Items    []FileInfo `json:"items"`
}

FileListResult holds paginated file list.

type Service

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

Service manages file system cache operations.

func NewService

func NewService(dataDir string, runtime *config.Runtime) *Service

NewService creates a new cache service. dataDir is the base data directory (e.g. "data"). Cache files are expected at {dataDir}/tmp/image and {dataDir}/tmp/video. runtime can be nil (all limits disabled).

func (*Service) Clear

func (s *Service) Clear(mediaType string) *ClearResult

Clear removes all whitelisted files from the cache directory.

func (*Service) DeleteFile

func (s *Service) DeleteFile(mediaType, name string) error

DeleteFile removes a single cached file.

func (*Service) DeleteFiles

func (s *Service) DeleteFiles(mediaType string, names []string) *BatchResult

DeleteFiles removes multiple cached files and returns success/failure counts.

func (*Service) FilePath

func (s *Service) FilePath(mediaType, name string) (string, error)

FilePath returns the absolute path to a cached file after validation. It also touches the file's mtime to support LRU eviction ordering.

func (*Service) GetStats

func (s *Service) GetStats(mediaType string) Stats

GetStats returns cache statistics for the given media type. Count is scanned from disk; SizeMB is read from sizeMap.

func (*Service) ListFiles

func (s *Service) ListFiles(mediaType string, page, pageSize int) (*FileListResult, error)

ListFiles returns a paginated list of cached files sorted by modification time.

func (*Service) SaveFile

func (s *Service) SaveFile(mediaType string, data []byte, ext string) (string, error)

SaveFile writes data to a new UUID-named file in the cache directory for the given media type. ext must include the leading dot (e.g. ".png", ".mp4"). Returns the generated filename (not the full path).

func (*Service) SaveStream

func (s *Service) SaveStream(mediaType string, reader io.Reader, ext string) (string, error)

SaveStream writes reader content to a new UUID-named file.

type Stats

type Stats struct {
	Count   int     `json:"count"`
	SizeMB  float64 `json:"size_mb"`
	LimitMB float64 `json:"limit_mb"`
}

Stats holds cache statistics for a media type.

Jump to

Keyboard shortcuts

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