Documentation
¶
Overview ¶
Package listcache keeps whole-library listings encoded on disk, so a protocol whose clients download a library in one response (Xtream's get_vod_streams) streams a file instead of reading, authorizing, signing and encoding the library again.
A listing fills a slot (what it lists, for whom, under which origin) and is stamped with its State: an exact stamp of every input but catalogue content, the catalogue generation it was read at, and whether the viewer's policy judges titles on their facts. A listing is served only to a request with the same stamp. Catalogue writes are bounded staleness: a listing read before one is served for up to Stale, and rebuilt behind the response, unless its policy is Judged; then the write retires it at once.
With no servable listing a request follows a build as it is written: the one in flight for its slot when that build reads what the request must see, otherwise one it starts. A follower receives bytes as the build writes them, so it never waits longer than encoding the library itself.
Listings are stamped with a process's generations and none outlives it: the directory is emptied when a store opens, and its size is capped.
Index ¶
Constants ¶
const ( // Stale is the longest a listing is served after it was read. Stale = 30 * time.Minute // Revalidate is the age, or a catalogue write, after which a served // listing is rebuilt behind the response. Revalidate = 2 * time.Minute // RenewEvery is how often a listing's artwork is re-armed for one // credential. Image grants live ten minutes. RenewEvery = 4 * time.Minute // Idle drops a listing nobody fetched for this long. Idle = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is one listing: written by its build, then served until it is retired. Its files are removed once it is retired and nobody reads them.
func (*Entry) KeepImages ¶
func (e *Entry) KeepImages(items []frontend.ImageBatchItem) error
KeepImages records one page's signed artwork beside the listing, so its image URLs can be re-armed for another credential, or once the grants SignPage issued expire. Pages may be signed concurrently.
type Request ¶
type Request struct {
Slot string
State State
// Owner names the requesting credential (its device). A listing's
// artwork is renewed for each owner at most once per RenewEvery.
Owner string
// Build encodes the listing as this request would, writing its body to
// the entry and its artwork with KeepImages. It runs at most once,
// after the request may have returned, under a context of its own.
Build func(context.Context, *Entry) error
// Renew re-arms a listing's artwork for Owner. Nil skips it.
Renew func(context.Context, *Entry) error
}
Request is one list request.
type State ¶
type State struct {
// Stamp covers every input but catalogue content: equal stamps mean
// the same policy, library and encoding.
Stamp string
// Catalog is the catalogue generation; Judged makes it exact.
Catalog uint64
Judged bool
At time.Time
}
State is what a listing was read under, or what a request needs.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is one frontend's listings.
func New ¶
New opens a store in dir, emptying it. It returns nil, and callers encode every listing, when dir is empty or unusable.
func (*Store) Close ¶
func (s *Store) Close()
Close stops builds and waits for the store's background work.