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
- Variables
- func BitmapKey(key string) string
- func FrameKey(project string, revision int64, frame, width int) string
- func FrameKeyHeight(project string, revision int64, frame, width, height int) string
- func SheetKey(project string, revision int64, keyHash string, width int) string
- type Store
Constants ¶
const DefaultMaxBytes int64 = 2 << 30
DefaultMaxBytes is the default of STUARTY_CACHE_MAX_BYTES: 2 GiB, shared by frames/ and bitmaps/.
const KeepRevisions = 5
KeepRevisions is how many revisions before the current one keep their frames (SDD-004 section 9).
Variables ¶
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 FrameKey ¶
FrameKey is the file of a frame: frames/<project>/<revision>/<frame>-<width>.jpg (SDD-000 section 9).
func FrameKeyHeight ¶
FrameKeyHeight is the file of a frame whose height is not the one the width gives: <frame>-<width>x<height>.jpg.
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 ¶
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) Lease ¶
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) PruneRevisions ¶
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.