Expresso.Element.Diagram.Cache (expresso v0.1.0)

Copy Markdown View Source

Keeps the SVG of each graph and the MathML of each formula from one render of the watch mode to the next

D2 with ELK takes some seconds for a graph, and the watch mode renders the whole deck after each change. Without a cache, a change to the text of one slide would run each tool of the deck again.

Expresso.Watch calls run/2 around each render, with the cache of the render before. fetch/2 returns the value of a key from that cache, or it calls its function. run/2 returns the entries that the render used, so the cache holds only the graphs of the deck as it is now. A render outside run/2, such as a render from the command line, runs each tool one time and keeps nothing.

The cache is in the process dictionary of the render, as the record of Expresso.DeckFile.track/1 is. A render runs in one process.

Summary

Types

t()

The entries of a cache, by key

Functions

Return the value of a key, or call the function and keep its value

Return the value of each key, and call the function one time for the keys that the cache does not hold

Run a render with the entries of the render before

Types

t()

@type t() :: %{required(binary()) => term()}

The entries of a cache, by key

Functions

fetch(key, function)

@spec fetch(term(), (-> value)) :: value when value: var

Return the value of a key, or call the function and keep its value

Outside run/2, the function calls function each time. The key is a term, and the function keeps a hash of it.

fetch_many(keys, function)

@spec fetch_many([term()], ([term()] -> [value])) :: [value] when value: var

Return the value of each key, and call the function one time for the keys that the cache does not hold

function takes the list of the missing keys, in the order of keys, and returns one value for each. A tool that makes many values in one run, such as Temml for the formulas of a deck, then runs one time. Outside run/2, the function calls function with each key.

run(cache, function)

@spec run(t(), (-> result)) :: {result, t()} when result: var

Run a render with the entries of the render before

The function returns the result of the render and the entries that the render used.