localcache

package
v0.80.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package localcache pre-fetches whole files from slow/remote mounts (rclone / Google Drive) onto fast local disk so playback is instant, seekable, and immune to the intermittent I/O errors the FUSE mount throws. Unlike rclone's own VFS cache — which only fills as bytes are read, so the FIRST play still pays the cold-start latency — this downloads the ENTIRE file up front when the user marks it, then serves it locally. The cache is size-capped with LRU eviction (like the torrent piece cache), so it never fills the disk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache stores fully-copied files under root, capped at maxBytes (LRU eviction).

func New

func New(root string, maxGB int) (*Cache, error)

New creates (or reopens) a cache rooted at root, capped at maxGB gigabytes (≤0 → 50 GiB default), and starts the copy worker. Existing ready files are reloaded from the on-disk index.

func (*Cache) CachedPath

func (c *Cache) CachedPath(mount, path string) (string, bool)

CachedPath returns the local cached path for (mount, path) when ready, and bumps its LRU recency so an actively-watched file isn't evicted.

func (*Cache) Close

func (c *Cache) Close()

Close stops the worker.

func (*Cache) Enqueue

func (c *Cache) Enqueue(mount, path, srcAbs string, size int64)

Enqueue marks (mount, path) for caching: copies srcAbs (the resolved on-disk path on the slow mount) to local disk in the background. A no-op if the file is already cached or in flight.

func (*Cache) Remove

func (c *Cache) Remove(mount, path string)

Remove drops a cached/queued entry and deletes its file.

func (*Cache) Root

func (c *Cache) Root() string

Root returns the cache's on-disk root directory. Callers use it to derive sibling caches (e.g. an extracted-subtitle VTT cache) that share the same fast-disk location without coupling to this package's internals.

func (*Cache) StatusFor

func (c *Cache) StatusFor(mount, path string) Snapshot

StatusFor returns the cache mark for (mount, path); Status "none" if absent.

type Snapshot

type Snapshot struct {
	Status  string `json:"status"` // "none" when there's no entry
	Size    int64  `json:"size"`
	Copied  int64  `json:"copied"`
	Percent int    `json:"percent"`
	Error   string `json:"error,omitempty"`
}

Snapshot is the JSON-friendly view returned to the UI (the "cache mark").

type Status

type Status string
const (
	StatusQueued  Status = "queued"
	StatusCopying Status = "copying"
	StatusReady   Status = "ready"
	StatusError   Status = "error"
)

Jump to

Keyboard shortcuts

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