cache

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache provides persistent storage for Plex media library data. It caches media items locally for fast offline browsing without requiring repeated API calls to the Plex server. The cache is stored as JSON in the user's config directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCachePath

func GetCachePath() (string, error)

GetCachePath returns the path to the cache file

func GetMetaPath added in v0.3.7

func GetMetaPath() (string, error)

GetMetaPath returns the path to the freshness sidecar file.

func SaveMeta added in v0.3.7

func SaveMeta(m CacheMeta) error

SaveMeta atomically writes the freshness sidecar. It's called by Save and by the LAN sync pull (which writes media.json directly, bypassing Save) so the sidecar always matches the cache on disk — preserving the original LastUpdated stamp rather than resetting it.

Types

type Cache

type Cache struct {
	// Media contains all cached media items from the Plex library
	Media []plex.MediaItem `json:"media"`
	// LastUpdated tracks when the cache was last refreshed from Plex
	LastUpdated time.Time `json:"last_updated"`
}

Cache stores media items and metadata about when the cache was last updated. Use Load() to read from disk and Save() to persist changes.

func Load

func Load() (*Cache, error)

Load reads the cache from disk

func (*Cache) ApplyOffsets added in v0.2.8

func (c *Cache) ApplyOffsets(offsets map[string]int) bool

ApplyOffsets writes playback positions (milliseconds, keyed by media key) into the matching cached items, updating ViewOffset and LastViewedAt. It is used after playback to flush progress into the local cache so items appear in "Continue Watching" immediately, without a full reindex. It returns true if any item was updated. Callers persist the change with Save().

func (*Cache) FormatForFzf

func (c *Cache) FormatForFzf() []string

FormatForFzf returns a slice of formatted strings for fzf

func (*Cache) GetMediaByFormattedTitle

func (c *Cache) GetMediaByFormattedTitle(formattedTitle string) (*plex.MediaItem, error)

GetMediaByFormattedTitle returns the media item matching the formatted title

func (*Cache) GetMediaByIndex

func (c *Cache) GetMediaByIndex(index int) (*plex.MediaItem, error)

GetMediaByIndex returns the media item at the given index

func (*Cache) GetMediaByTitle

func (c *Cache) GetMediaByTitle(title string) []plex.MediaItem

GetMediaByTitle returns media items that match the given title

func (*Cache) IsStale

func (c *Cache) IsStale(maxAge time.Duration) bool

IsStale checks if the cache is older than the given duration

func (*Cache) Save

func (c *Cache) Save() error

Save writes the cache to disk

type CacheMeta added in v0.3.7

type CacheMeta struct {
	Count       int       `json:"count"`
	LastUpdated time.Time `json:"last_updated"`
}

CacheMeta is a tiny freshness summary written alongside media.json (meta.json) so a process can report how big and how fresh its cache is without reading the whole file. It powers the LAN cache-sync freshness comparison.

func LoadMeta added in v0.3.7

func LoadMeta() (CacheMeta, error)

LoadMeta reads the freshness sidecar. A missing sidecar is not an error: it returns a zero CacheMeta (count 0, zero time), which compares as "older than anything" for sync purposes.

Jump to

Keyboard shortcuts

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