Small ETS-backed cache for Imp's configurable cache concept.
In normal production use the Imp OTP application supervises the cache owner process. The ETS table is public for fast concurrent reads and writes, but its lifecycle belongs to that owner process. If the owner crashes, the table is recreated by the restarted process and cached values are intentionally lost. Calling cache functions before the application is started attempts to start the application.
fetch_or_store/2 coalesces concurrent misses per key. The first caller computes
the value while other callers wait without blocking unrelated keys. Producers are
monitored so a crash promotes one waiting caller and does not strand the rest.
Summary
Functions
Returns a specification to start this module under a supervisor.
Removes all cached values from the current ETS table.
Ensures the cache owner and ETS table are available.
Returns a cached value or computes, stores, and returns a miss.
Reads a cached value or returns default.
Returns the active cache policy.
Stores a value and returns the stored value.
Resets cache usage counters without removing entries.
Returns cache usage counters and current entry count.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Removes all cached values from the current ETS table.
Cache contents are process-local operational state, not durable storage.
Ensures the cache owner and ETS table are available.
Calling cache APIs before the :imp application is started lazily starts the
application when possible.
Returns a cached value or computes, stores, and returns a miss.
Concurrent misses for the same key are coalesced into one computation. If that producer fails or exits, one waiting caller is promoted to compute the value. Cache hit, miss, coalesced-wait, retry, and producer-failure telemetry is emitted with redacted metadata.
iex> Imp.Cache.clear()
:ok
iex> Imp.Cache.fetch_or_store(:cache_doctest_fetch, fn -> :computed end)
:computed
iex> Imp.Cache.fetch_or_store(:cache_doctest_fetch, fn -> :different end)
:computed
Reads a cached value or returns default.
iex> Imp.Cache.put(:cache_doctest_get, :cached)
:cached
iex> Imp.Cache.get(:cache_doctest_get)
:cached
iex> Imp.Cache.get(:cache_doctest_missing, :fallback)
:fallback
Returns the active cache policy.
Stores a value and returns the stored value.
iex> Imp.Cache.put(:cache_doctest_put, %{answer: 42})
%{answer: 42}
Resets cache usage counters without removing entries.
Returns cache usage counters and current entry count.