Documentation
¶
Overview ¶
Package cache provides file system cache management for image and video files.
Index ¶
- Variables
- type BatchResult
- type ClearResult
- type FileInfo
- type FileListResult
- type Service
- func (s *Service) Clear(mediaType string) *ClearResult
- func (s *Service) DeleteFile(mediaType, name string) error
- func (s *Service) DeleteFiles(mediaType string, names []string) *BatchResult
- func (s *Service) FilePath(mediaType, name string) (string, error)
- func (s *Service) GetStats(mediaType string) Stats
- func (s *Service) ListFiles(mediaType string, page, pageSize int) (*FileListResult, error)
- func (s *Service) SaveFile(mediaType string, data []byte, ext string) (string, error)
- func (s *Service) SaveStream(mediaType string, reader io.Reader, ext string) (string, error)
- type Stats
Constants ¶
This section is empty.
Variables ¶
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 ¶
BatchResult holds results of batch delete.
type ClearResult ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.