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/cache_policy/manual.ex
defmodule ConfigCat.CachePolicy.Manual do
@moduledoc false
use GenServer
alias ConfigCat.{CachePolicy, Constants}
alias ConfigCat.CachePolicy.{Behaviour, Helpers}
require Constants
defstruct mode: "m"
@type t :: %__MODULE__{mode: String.t()}
@behaviour Behaviour
@spec new :: t()
def new do
%__MODULE__{}
end
@spec start_link(CachePolicy.options()) :: GenServer.on_start()
def start_link(options) do
Helpers.start_link(__MODULE__, options)
end
@impl GenServer
def init(state) do
{:ok, state}
end
@impl Behaviour
def get(policy_id) do
GenServer.call(policy_id, :get)
end
@impl Behaviour
def force_refresh(policy_id) do
GenServer.call(policy_id, :force_refresh, Constants.fetch_timeout())
end
@impl GenServer
def handle_call(:get, _from, state) do
{:reply, Helpers.cached_config(state), state}
end
@impl GenServer
def handle_call(:force_refresh, _from, state) do
case Helpers.refresh_config(state) do
:ok ->
{:reply, :ok, state}
error ->
{:reply, error, state}
end
end
end