Packages
ConfigCat SDK for Elixir. Feature Flags created by developers for developers with ❤️. ConfigCat lets you manage feature flags across frontend, backend, mobile, and desktop apps without (re)deploying code. % rollouts, user targeting, segmentation. Feature toggle SDKs for all main languages.
Current section
Files
Jump to
Current section
Files
lib/config_cat/in_memory_cache.ex
defmodule ConfigCat.InMemoryCache do
@moduledoc false
use GenServer
alias ConfigCat.ConfigCache
@type option :: {:cache_key, ConfigCache.key()}
@type options :: [option]
@behaviour ConfigCache
@spec start_link(options()) :: GenServer.on_start()
def start_link(options) do
name =
options
|> Keyword.fetch!(:cache_key)
|> name_from_cache_key()
GenServer.start_link(__MODULE__, :empty, name: name)
end
@impl ConfigCache
def get(cache_key) do
GenServer.call(name_from_cache_key(cache_key), :get)
end
@impl ConfigCache
def set(cache_key, value) do
GenServer.call(name_from_cache_key(cache_key), {:set, value})
end
defp name_from_cache_key(cache_key) do
String.to_atom(cache_key)
end
@impl GenServer
def init(state) do
{:ok, state}
end
@impl GenServer
def handle_call(:get, _from, :empty = state) do
{:reply, {:error, :not_found}, state}
end
@impl GenServer
def handle_call(:get, _from, state) do
{:reply, {:ok, state}, state}
end
@impl GenServer
def handle_call({:set, value}, _from, _state) do
{:reply, :ok, value}
end
end