# `Cache.CaseTemplate`
[🔗](https://github.com/mikaak/elixir_cache/blob/main/lib/cache/case_template.ex#L1)

A reusable ExUnit case template for applications using `elixir_cache`.

Creates a `CacheCase` module that automatically starts sandboxed caches in
`setup` for every test that uses it.

## Creating a CacheCase module

Pass an explicit list of cache modules:

```elixir
defmodule MyApp.CacheCase do
  use Cache.CaseTemplate, default_caches: [MyApp.UserCache, MyApp.SessionCache]
end
```

Or discover caches at runtime by inspecting a running supervisor:

```elixir
defmodule MyApp.CacheCase do
  use Cache.CacheTemplate, supervisors: [MyApp.Supervisor]
end
```

## Using the CacheCase in a test file

```elixir
defmodule MyApp.SomeTest do
  use ExUnit.Case, async: true
  use MyApp.CacheCase

  # or with additional caches just for this file:
  use MyApp.CacheCase, caches: [MyApp.ExtraCache]
end
```

## Options for `use Cache.CaseTemplate`

- `:default_caches` — list of cache modules to start for every test
- `:supervisors` — list of supervisor atoms; their `Cache` children are discovered at runtime

## Options for `use MyApp.CacheCase`

- `:caches` — additional cache modules for this test file only
- `:sleep` — milliseconds to sleep after starting caches (default: `10`)

# `inferred_caches`

```elixir
@spec inferred_caches([atom()] | atom()) :: [module()]
```

Inspects a running supervisor's children to find cache modules started under a
`Cache` supervisor child.

Raises if the given supervisor is not running or has no `Cache` child.

# `validate_uniq!`

```elixir
@spec validate_uniq!([module()]) :: [module()]
```

Validates that the list of cache modules contains no duplicates.

Raises with a descriptive message listing the duplicates if any are found.

---

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