ETS-based cache for expensive dashboard aggregations.
Provides TTL-based caching with automatic expiration to reduce database load for frequently accessed metrics.
Summary
Functions
Returns a specification to start this module under a supervisor.
Gets a cached value, or computes and caches it if not present or expired.
Invalidates all cache entries matching a pattern.
Starts the metrics cache.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
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)
@spec invalidate_pattern(term()) :: :ok
Invalidates all cache entries matching a pattern.
Examples
MetricsCache.invalidate_pattern(:overview_metrics)
MetricsCache.invalidate_pattern({:flow_stats, _})
Starts the metrics cache.