Default allowlist of cacheable read-only Redis commands and helpers for normalizing user-provided cacheable configuration.
The allowlist contains single-key read-only commands where the first
argument after the command name is the Redis key. Multi-key commands
like MGET, SDIFF, and SINTER are excluded (MGET has its own
specialized handler in Redis.Cache).
Configuration Formats
The :cacheable option accepts three formats:
:default- uses the built-in allowlist with no per-command TTL overrides- A list of command entries:
["GET", "HGETALL", {"LRANGE", ttl: 5_000}] - A function for full control:
fn ["GET" | _] -> true; ["LRANGE" | _] -> {:ok, 5_000}; _ -> false end
Summary
Functions
Checks if a command is cacheable and returns its TTL override (if any).
Returns the default set of cacheable command names.
Normalizes the :cacheable option into an internal representation.
Functions
@spec check({:map, map()} | {:function, fun()}, [String.t()]) :: {:ok, non_neg_integer() | nil} | :nocache
Checks if a command is cacheable and returns its TTL override (if any).
Returns:
{:ok, ttl}where ttl isnil(use global) or a positive integer:nocache
@spec default_commands() :: [String.t()]
Returns the default set of cacheable command names.
@spec normalize(term()) :: {:map, %{required(String.t()) => non_neg_integer() | nil}} | {:function, fun()}
Normalizes the :cacheable option into an internal representation.
Returns either:
{:map, %{command => ttl | nil}}for list/default configs{:function, fun}for function configs