# `AshCache.Key`
[🔗](https://github.com/Undeadlol1/ash_cache/blob/v0.1.0/lib/ash_cache/key.ex#L1)

Builds deterministic cache keys for cached read and generic actions.

A key is a plain Erlang term (no hashing, so no collision risk) built from:

  * the resource module
  * the resource's current cache version (see `AshCache.CacheVersion`)
  * the action name
  * the whole query shape — arguments, `filter`, `sort`, `limit`, `offset`,
    `page`, `distinct`, `select`, `load`, `calculations` and
    `aggregates` (assembled in
    `AshCache.Preparations.ReadThrough`). `filter` is the load-bearing one:
    the policy authorizer has already folded its filter checks into it by
    the time the key is derived, so it is what stops an unauthorized read
    from being answered by an authorized one — not merely what tells two
    queries apart
  * for a generic action, only its arguments take the place of the query
    shape (`AshCache.Actions.RunThrough`)
  * for a calculation, `{:calculation, name}` takes the place of the
    action name, and the shape is one record's attributes, the fields the
    calculation loads and its arguments
    (`AshCache.Calculations.CalculateThrough`); there is no version
  * the actor and tenant, so cached results never leak across actors
    or tenants

# `t`

```elixir
@type t() ::
  {:ash_cache, resource :: module(), version :: term(), action :: atom(),
   query_shape :: term(), actor_ref :: term(), tenant_ref :: term()}
```

# `build`

```elixir
@spec build(module(), atom() | {:calculation, atom()}, map(), term(), keyword()) ::
  t()
```

---

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