ETS-backed cache for decoded and encoded terminal images.
Caches expensive operations:
- PNG decode results (raw pixel data)
- Sixel/Kitty encoded output for given parameters
Keys are {content_hash, opts_hash} tuples. Entries expire after a
configurable TTL (default 5 minutes). The cache is created lazily on
first access and owned by the calling process (or an explicit owner).
Usage
ImageCache.start()
ImageCache.put("img.png", png_bytes, %{max_colors: 64})
{:ok, cached} = ImageCache.get("img.png", %{max_colors: 64})
ImageCache.evict("img.png")
Summary
Functions
Deletes all entries from the cache.
Removes all entries matching a source identifier (any opts).
Fetches from cache or computes and caches the value.
Retrieves a cached value. Returns {:ok, value} or :miss.
Expired entries are transparently deleted.
Removes all expired entries from the cache.
Stores a value in the cache keyed by source identifier and options.
Returns the number of entries currently in the cache.
Creates the ETS table if it doesn't already exist. Safe to call multiple times.
Types
Functions
@spec clear() :: :ok
Deletes all entries from the cache.
@spec evict(binary()) :: :ok
Removes all entries matching a source identifier (any opts).
@spec fetch(binary(), map(), (-> {:ok, term()} | {:error, term()})) :: {:ok, term()} | {:error, term()}
Fetches from cache or computes and caches the value.
The compute_fn is called only on cache miss and must return
{:ok, value} or {:error, reason}.
Retrieves a cached value. Returns {:ok, value} or :miss.
Expired entries are transparently deleted.
@spec prune() :: non_neg_integer()
Removes all expired entries from the cache.
Stores a value in the cache keyed by source identifier and options.
@spec size() :: non_neg_integer()
Returns the number of entries currently in the cache.
@spec start() :: :ok
Creates the ETS table if it doesn't already exist. Safe to call multiple times.