# `PgFlowDashboard.Cache.MetricsCache`
[🔗](https://github.com/agoodway/pgflow/blob/v0.1.0/lib/pgflow_dashboard/cache/metrics_cache.ex#L1)

ETS-based cache for expensive dashboard aggregations.

Provides TTL-based caching with automatic expiration to reduce
database load for frequently accessed metrics.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `fetch`

```elixir
@spec fetch(term(), (-&gt; term()), keyword()) :: term()
```

Gets a cached value, or computes and caches it if not present or expired.

Uses a "single-flight" pattern to prevent cache stampede: when a cache miss
occurs, the computation is serialized through the GenServer so only one
caller computes the value while others wait for the result.

## Options

  * `:ttl` - Time-to-live in milliseconds. Default: 5000ms.

## Examples

    MetricsCache.fetch(:overview_metrics, fn -> Queries.get_overview_metrics(repo) end)

# `invalidate_pattern`

```elixir
@spec invalidate_pattern(term()) :: :ok
```

Invalidates all cache entries matching a pattern.

## Examples

    MetricsCache.invalidate_pattern(:overview_metrics)
    MetricsCache.invalidate_pattern({:flow_stats, _})

# `start_link`

Starts the metrics cache.

---

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