Routemaster Client v0.3.0 Routemaster.Cache View Source
A persistent cache that survives application restarts, backed by Redis.
Link to this section Summary
Functions
It clears a key-value from the cache
Tries to read key
from the cache, and returns the stored value
if anything is found. If no vlaue is found in the cache, it
executes the fallback
function, caches the result, and returns
the value in a tuple
Reads a key-value and returns an Elixr term, in a tuple
Writes a key-value and returns the written value, in a tuple
Link to this section Types
Link to this section Functions
It clears a key-value from the cache
iex> Routemaster.Cache.write(:mango, "so good")
{:ok, "so good"}
iex> Routemaster.Cache.clear(:mango)
:ok
iex> Routemaster.Cache.read(:mango)
{:miss, nil}
Tries to read key
from the cache, and returns the stored value
if anything is found. If no vlaue is found in the cache, it
executes the fallback
function, caches the result, and returns
the value in a tuple.
iex> Routemaster.Cache.read(:peach)
{:miss, nil}
iex> Routemaster.Cache.fetch(:peach, fn() -> "apricot" end)
{:ok, "apricot"}
iex> Routemaster.Cache.fetch(:peach, fn() -> "coconut" end)
{:ok, "apricot"}
iex> Routemaster.Cache.read(:peach)
{:ok, "apricot"}
Reads a key-value and returns an Elixr term, in a tuple.
iex> Routemaster.Cache.read(:apple)
{:miss, nil}
iex> Routemaster.Cache.write(:apple, %{is: "a", good: "fruit"})
{:ok, %{is: "a", good: "fruit"}}
iex> Routemaster.Cache.read(:apple)
{:ok, %{is: "a", good: "fruit"}}
Writes a key-value and returns the written value, in a tuple.
iex> Routemaster.Cache.write(:pear, [1, 2, 3])
{:ok, [1, 2, 3]}
iex> Routemaster.Cache.read(:pear)
{:ok, [1, 2, 3]}