Unified cache interface — ETS, Redis, Memcached.
Provides a consistent API for different cache backends via the
Apero.Cache.Adapter behaviour.
Supported backends
Apero.Cache.ETS— in-memory ETS with TTL (built-in, no deps)Apero.Cache.Redis— Redis viaredix(optional dep)Apero.Cache.Memcached— Memcached viamemcache(optional dep)
Usage
# ETS (built-in)
{:ok, pid} = Apero.Cache.start_link(Apero.Cache.ETS, name: :my_cache)
Apero.Cache.put(:my_cache, "key", "value", ttl: 3600)
Apero.Cache.get(:my_cache, "key") # => {:ok, "value"}
# Redis
Apero.Cache.put(:redis_cache, "key", "value")
Summary
Functions
Deletes a key.
Fetches or computes a value (cache-aside pattern).
Clears all keys.
Retrieves a value. Returns {:ok, value} or {:error, :not_found}.
Returns true if the key exists.
Stores a value. Optional :ttl in seconds.
Returns the number of keys.
Starts a cache backend. Returns {:ok, pid}.
Types
Functions
@spec delete(cache_name(), term()) :: :ok | {:error, term()}
Deletes a key.
Fetches or computes a value (cache-aside pattern).
@spec flush(cache_name()) :: :ok | {:error, term()}
Clears all keys.
@spec get(cache_name(), term()) :: {:ok, term()} | {:error, :not_found}
Retrieves a value. Returns {:ok, value} or {:error, :not_found}.
@spec member?(cache_name(), term()) :: boolean()
Returns true if the key exists.
@spec put(cache_name(), term(), term(), keyword()) :: :ok | {:error, term()}
Stores a value. Optional :ttl in seconds.
@spec size(cache_name()) :: {:ok, non_neg_integer()} | {:error, term()}
Returns the number of keys.
@spec start_link( module(), keyword() ) :: GenServer.on_start()
Starts a cache backend. Returns {:ok, pid}.