Bandera.Store.Cache (bandera v0.1.0)

Copy Markdown

ETS read cache for flags. Always started; bypassed by the store when the cache is disabled (so the cache can be toggled at runtime without races). The TTL is read from the runtime Bandera.Config snapshot at lookup time.

Note: a TTL of 0 causes every entry to expire immediately on the next read (it is not "no expiry"). To disable caching entirely, set cache: [enabled: false].

Summary

Functions

Evicts a single flag's cache entry. Used by cache-busting notifications.

Returns a specification to start this module under a supervisor.

Evicts every cache entry.

Reads a flag from the cache.

Caches flag with a fresh timestamp and returns it unchanged (for pipelining).

Starts the cache GenServer (which owns the backing ETS table) under its module name.

Functions

bust(flag_name)

@spec bust(atom()) :: :ok

Evicts a single flag's cache entry. Used by cache-busting notifications.

Examples

iex> Bandera.Store.Cache.put(Bandera.Flag.new(:demo, []))
iex> Bandera.Store.Cache.bust(:demo)
:ok
iex> Bandera.Store.Cache.get(:demo)
{:miss, :not_found}

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush()

@spec flush() :: :ok

Evicts every cache entry.

Examples

iex> Bandera.Store.Cache.put(Bandera.Flag.new(:demo, []))
iex> Bandera.Store.Cache.flush()
:ok
iex> Bandera.Store.Cache.get(:demo)
{:miss, :not_found}

get(flag_name)

@spec get(atom()) :: {:ok, Bandera.Flag.t()} | {:miss, :not_found | :expired}

Reads a flag from the cache.

Returns {:ok, flag} on a live hit, or {:miss, :not_found} / {:miss, :expired} so the caller can fall through to the persistent store. Expiry is evaluated against the current Bandera.Config.cache_ttl/0 at read time.

Examples

iex> Bandera.Store.Cache.get(:absent)
{:miss, :not_found}

iex> Bandera.Store.Cache.put(Bandera.Flag.new(:demo, []))
iex> Bandera.Store.Cache.get(:demo)
{:ok, %Bandera.Flag{name: :demo, gates: []}}

put(flag)

@spec put(Bandera.Flag.t()) :: Bandera.Flag.t()

Caches flag with a fresh timestamp and returns it unchanged (for pipelining).

Examples

iex> Bandera.Store.Cache.put(Bandera.Flag.new(:demo, []))
%Bandera.Flag{name: :demo, gates: []}

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the cache GenServer (which owns the backing ETS table) under its module name.