cache

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 12 Imported by: 1 module, 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 is the byte-capped, least-recently-used file cache of the frames and bitmaps the service renders (SDD-007 section 9.1, threat T-19). Only the files under its root are ever removed, and nothing else is: stores, artifacts and exports live elsewhere.

Index

Constants

View Source
const DefaultMaxBytes int64 = 2 << 30

DefaultMaxBytes is the default of STUARTY_CACHE_MAX_BYTES: 2 GiB, shared by frames/ and bitmaps/.

View Source
const KeepRevisions = 5

KeepRevisions is how many revisions before the current one keep their frames (SDD-004 section 9).

Variables

View Source
var ErrKey = errors.New("cache: invalid key")

ErrKey is returned for a key that is not a plain relative slash path inside the cache.

Functions

func BitmapKey

func BitmapKey(key string) string

BitmapKey is the file of a rasterized bitmap: bitmaps/<key>.png.

func FrameKey

func FrameKey(project string, revision int64, frame, width int) string

FrameKey is the file of a frame: frames/<project>/<revision>/<frame>-<width>.jpg (SDD-000 section 9).

func FrameKeyHeight

func FrameKeyHeight(project string, revision int64, frame, width, height int) string

FrameKeyHeight is the file of a frame whose height is not the one the width gives: <frame>-<width>x<height>.jpg.

func SheetKey

func SheetKey(project string, revision int64, keyHash string, width int) string

SheetKey is the file of a contact sheet: sheet-<first 12 hex of the key hash>-<width>.jpg in the folder of the revision (SDD-003 section 3.11, item 5).

Types

type Store

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

Store is a directory of cached files with a byte cap. Reading a file makes it the most recently used; writing past the cap removes the least recently used files first. It is safe for concurrent use.

func Open

func Open(root string, maxBytes int64) (*Store, error)

Open uses root as the cache directory, creating it, and indexes what is already there by modification time (a read touches the file, so that is the order of use). A cap of zero or less is DefaultMaxBytes. Files over the cap are evicted at once.

func (*Store) Get

func (s *Store) Get(key string) ([]byte, bool)

Get returns the cached bytes of key and marks them most recently used.

func (*Store) Lease

func (s *Store) Lease(key string) (release func())

Lease marks key as in use: eviction and pruning skip it until the returned function is called. A running export holds a lease on every file it reads (SDD-007 9.1), so the cap never takes a file from under it. The cache may pass its cap while files are leased.

func (*Store) Max

func (s *Store) Max() int64

Max is the cap in bytes.

func (*Store) PruneRevisions

func (s *Store) PruneRevisions(project string, keep int)

PruneRevisions deletes the frame directories of project that are older than the newest keep+1 revisions, that is the current one and the previous keep. A directory that holds a leased file stays. It is called after every frame write with KeepRevisions.

func (*Store) Put

func (s *Store) Put(key string, data []byte) error

Put stores data under key, replacing what was there, and evicts least recently used files until the cache fits its cap again. Data larger than the cap is not stored.

func (*Store) Size

func (s *Store) Size() int64

Size is the bytes the cache holds.

Jump to

Keyboard shortcuts

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