# `TuningFork.Cache`
[🔗](https://github.com/jaman/tuning_fork/blob/v0.1.11/tuning_fork/lib/tuning_fork/cache.ex#L1)

Keeps rendered audio on disk, keyed by name and fingerprint, in a directory the
caller names — an application keeps its own — or this library's own when none is.

    Cache.fetch("dusk", Cache.fingerprint(MyApp.Music), fn -> render() end, dir: "~/.cache/myapp/music")

# `clear`

```elixir
@spec clear() :: :ok
```

Remove the cache directory and everything in it, whatever fingerprint it was stored under.

# `dir`

```elixir
@spec dir() :: Path.t()
```

The directory audio is kept in: `$XDG_STATE_HOME/tuning_fork`, or
`~/.local/state/tuning_fork` when that is unset or relative.

# `fetch`

```elixir
@spec fetch(String.t(), String.t(), (-&gt; binary()), keyword()) :: binary()
```

The stored audio for `key`, rendering and storing it when there is none.

`key` names the audio and may contain path separators. `fingerprint` is any string that
changes when the rendered result should change. `render` is called only on a miss, and its
binary is both stored and returned; an earlier fingerprint of the same key is removed. A
store that fails is logged at debug level and the binary is still returned. `:dir` is
the directory to keep it in, default `dir/0`.

# `fingerprint`

```elixir
@spec fingerprint(module()) :: String.t()
```

A fingerprint of `module`, as a hexadecimal string.

Changes when the compiled code of `module`, `TuningFork.Voice` or `TuningFork.Mixer` changes.

# `path`

```elixir
@spec path(String.t(), String.t(), Path.t()) :: Path.t()
```

Where `key` at `fingerprint` is kept, under `dir` (default `dir/0`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
