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 AudioPreviewKey(key string) string
- 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
- func (s *Store) Commit(key string) error
- func (s *Store) Get(key string) ([]byte, bool)
- func (s *Store) Has(key string) bool
- func (s *Store) Lease(key string) (release func())
- func (s *Store) Max() int64
- func (s *Store) PartPath(key string) (string, error)
- func (s *Store) PruneRevisions(project string, keep int)
- func (s *Store) Put(key string, data []byte) error
- func (s *Store) Size() int64
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 AudioPreviewKey ¶ added in v0.39.0
AudioPreviewKey is the file of the processed sound of an item: audio-previews/<key>.wav (SDD-004 section 7.1).
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) Commit ¶ added in v0.39.0
Commit renames the file written at PartPath(key) to its name, and counts its size, so that the cache evicts least recently used files until it fits its cap again. A file larger than the cap is removed and is not stored.
func (*Store) Has ¶ added in v0.39.0
Has reports whether key is stored, and makes it the most recently used. It reads no byte.
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) PartPath ¶ added in v0.39.0
PartPath is the path a file of key is written to before Commit: the final path with ".part" after it, in the folder of the key, which is made. A writer that is too big for the cache, or that fails, leaves only that name, which the next start indexes like any other file (SDD-011 section 6.4).
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.