# `Juggernaut.Cache.Footprint`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/cache/footprint.ex#L1)

Function hashes, and the footprint a cached result rests on (design notes §7.3).

A function's hash is the SHA-256 of its module's *context* (every module-body
expression that is not a function clause, a nested module or a documentation
attribute: `use`, `import`, `alias`, attributes, `defstruct`, ...) and all its clauses
in source order, as Sourceror parses them with every node's metadata stripped. So a
comment, a blank line or a layout change keeps the hash; an edit in the function, or in
what its module gives it (an attribute it reads, an alias it calls through), changes it.

A function the source does not write (`__struct__/0`, a default-argument arity, a
schemata copy) resolves to its module's context hash, and a module the file does not
define (or a file that does not parse) to the hash of the whole file: never a hash that
could stay the same while the code behind it changed.

A footprint, as recorded in a cache entry, is `%{file => %{"sha" => content sha,
"functions" => %{key => hash}}}`, keys as `key/3` makes them. It stands while every
file's content is unchanged, or, where the content changed, every recorded function
hashes the same.

# `current`

```elixir
@type current() :: %{
  required(String.t()) =&gt; %{sha: String.t(), hashes: hashes() | nil} | nil
}
```

Each file of the footprints looked at: its content sha and, if needed, its hashes.

# `function_ref`

```elixir
@type function_ref() :: {file :: String.t(), module(), atom(), arity()}
```

# `hashes`

```elixir
@type hashes() :: %{
  sha: String.t(),
  functions: %{required(String.t()) =&gt; String.t()},
  modules: %{required(String.t()) =&gt; String.t()}
}
```

# `recorded`

```elixir
@type recorded() :: %{required(String.t()) =&gt; %{required(String.t()) =&gt; term()}}
```

# `complete?`

```elixir
@spec complete?(recorded(), [function_ref()]) :: boolean()
```

Whether `recorded` names every file of `functions`.

# `current`

```elixir
@spec current(Path.t(), [recorded()]) :: current()
```

The current state of every file in `footprints` (recorded footprints): its content sha,
and its hashes only when its content differs from a sha some footprint recorded. `nil`
for a file that cannot be read.

# `file`

```elixir
@spec file(String.t()) :: hashes()
```

The hashes of every function and module of `source`.

# `key`

```elixir
@spec key(module() | String.t(), atom(), arity()) :: String.t()
```

The footprint key of a function: `"Elixir.Mod|fun/arity"`.

# `record`

```elixir
@spec record(Path.t(), [function_ref()]) :: recorded()
```

The footprint of `functions` (`{file, module, fun, arity}`, files relative to `root`)
as the files under `root` are now. A file that cannot be read is left out, which no
later footprint check can confirm, so callers record no entry for it (`complete?/2`).

# `recorded`

```elixir
@spec recorded(%{required(String.t()) =&gt; hashes() | nil}, [function_ref()]) ::
  recorded()
```

The footprint of `functions` from `scans` (`scan/2` of their files). As in `record/2`,
a file `scans` holds no hashes for (unreadable, or not scanned) is left out.

# `resolve`

```elixir
@spec resolve(hashes(), String.t()) :: String.t()
```

The hash of `key` in a file's `hashes`: the function's own, else its module's context
hash, else `"file:"` and the file's content hash.

# `scan`

```elixir
@spec scan(Path.t(), [String.t()]) :: %{required(String.t()) =&gt; hashes() | nil}
```

The hashes of each of `files` (relative to `root`) as it is now, `nil` for a file that
cannot be read. Each file is parsed once, in parallel, so a run that records many
footprints over the same files (`recorded/2`) parses a file once, not once per
footprint.

# `stands?`

```elixir
@spec stands?(recorded(), current()) :: boolean()
```

Whether a recorded footprint stands against `current` (see the module doc).

---

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