Module-based cache instances for FerricStore.
Each module that calls use FerricStore gets a local direct cache instance
with its own shards, ETS tables, data directory, and config. The default
application instance owns the Raft system.
Usage
defmodule MyApp.Cache do
use FerricStore,
data_dir: "/data/cache",
shard_count: 4,
max_memory: "1GB"
end
# In your supervision tree:
children = [MyApp.Cache]
# Then use it:
MyApp.Cache.set("key", "value")
{:ok, "value"} = MyApp.Cache.get("key")Multiple instances
defmodule MyApp.Sessions do
use FerricStore,
data_dir: "/data/sessions",
shard_count: 2
end
MyApp.Cache.set("page:home", html)
MyApp.Sessions.set("sess:abc", session_data)Options
:data_dir— base directory for Bitcask data files (required):shard_count— number of shards (default: 4):max_memory_bytes— maximum memory budget (default: 1GB):keydir_max_ram— maximum ETS keydir memory (default: 256MB):eviction_policy—:volatile_lfu|:allkeys_lfu|:noeviction(default::volatile_lfu):hot_cache_max_value_size— max value size for ETS caching (default: 65536):read_sample_rate— LFU sampling rate (default: 100):flow_retention_sweeper— per-instance Flow timeout/retention sweeper options such as:initial_delay_ms,:interval_ms, and:limit
Summary
Functions
Blocks until FerricStore is fully ready to serve requests.
See FerricStore.API.Generic.dbsize/0.
See FerricStore.API.System.echo/1.
See FerricStore.API.Flow.flow_approval_approve/2.
See FerricStore.API.Flow.flow_approval_get/2.
See FerricStore.API.Flow.flow_approval_list/1.
See FerricStore.API.Flow.flow_approval_reject/2.
See FerricStore.API.Flow.flow_approval_request/2.
See FerricStore.API.Flow.flow_attribute_values/3.
See FerricStore.API.Flow.flow_attributes/2.
See FerricStore.API.Flow.flow_budget_commit/4.
See FerricStore.API.Flow.flow_budget_get/2.
See FerricStore.API.Flow.flow_budget_list/1.
See FerricStore.API.Flow.flow_budget_release/3.
See FerricStore.API.Flow.flow_budget_reserve/3.
See FerricStore.API.Flow.flow_by_correlation/2.
See FerricStore.API.Flow.flow_by_parent/2.
See FerricStore.API.Flow.flow_by_root/2.
See FerricStore.API.Flow.flow_cancel/2.
See FerricStore.API.Flow.flow_cancel_many/3.
See FerricStore.API.Flow.flow_circuit_close/2.
See FerricStore.API.Flow.flow_circuit_get/2.
See FerricStore.API.Flow.flow_circuit_list/1.
See FerricStore.API.Flow.flow_circuit_open/2.
See FerricStore.API.Flow.flow_claim_due/2.
See FerricStore.API.Flow.flow_complete/3.
See FerricStore.API.Flow.flow_complete_many/3.
See FerricStore.API.Flow.flow_create/2.
See FerricStore.API.Flow.flow_create_many/3.
See FerricStore.API.Flow.flow_effect_compensate/3.
See FerricStore.API.Flow.flow_effect_confirm/3.
See FerricStore.API.Flow.flow_effect_fail/3.
See FerricStore.API.Flow.flow_effect_get/3.
See FerricStore.API.Flow.flow_effect_reserve/4.
See FerricStore.API.Flow.flow_extend_lease/3.
See FerricStore.API.Flow.flow_fail/3.
See FerricStore.API.Flow.flow_fail_many/3.
See FerricStore.API.Flow.flow_failures/2.
See FerricStore.API.Flow.flow_get/2.
See FerricStore.API.Flow.flow_governance_ledger/2.
See FerricStore.API.Flow.flow_governance_overview/1.
See FerricStore.API.Flow.flow_history/2.
See FerricStore.API.Flow.flow_info/2.
See FerricStore.API.Flow.flow_limit_get/2.
See FerricStore.API.Flow.flow_limit_lease/2.
See FerricStore.API.Flow.flow_limit_list/1.
See FerricStore.API.Flow.flow_limit_release/2.
See FerricStore.API.Flow.flow_limit_spend/2.
See FerricStore.API.Flow.flow_list/2.
See FerricStore.API.Flow.flow_policy_get/2.
See FerricStore.API.Flow.flow_policy_set/2.
See FerricStore.API.Flow.flow_reclaim/2.
See FerricStore.API.Flow.flow_retention_cleanup/1.
See FerricStore.API.Flow.flow_retry/3.
See FerricStore.API.Flow.flow_retry_many/3.
See FerricStore.API.Flow.flow_rewind/2.
See FerricStore.API.Flow.flow_run_steps_many/2.
See FerricStore.API.Flow.flow_schedule_create/2.
See FerricStore.API.Flow.flow_schedule_delete/2.
See FerricStore.API.Flow.flow_schedule_fire/2.
See FerricStore.API.Flow.flow_schedule_fire_due/1.
See FerricStore.API.Flow.flow_schedule_get/2.
See FerricStore.API.Flow.flow_schedule_list/1.
See FerricStore.API.Flow.flow_schedule_pause/2.
See FerricStore.API.Flow.flow_schedule_resume/2.
See FerricStore.API.Flow.flow_search/1.
See FerricStore.API.Flow.flow_signal/2.
See FerricStore.API.Flow.flow_spawn_children/3.
See FerricStore.API.Flow.flow_start_and_claim/4.
See FerricStore.API.Flow.flow_stats/2.
See FerricStore.API.Flow.flow_step_continue/5.
See FerricStore.API.Flow.flow_stuck/2.
See FerricStore.API.Flow.flow_terminals/2.
See FerricStore.API.Flow.flow_transition/4.
See FerricStore.API.Flow.flow_transition_many/5.
See FerricStore.API.Flow.flow_value_mget/2.
See FerricStore.API.Flow.flow_value_put/2.
See FerricStore.API.System.flushall/0.
See FerricStore.API.Generic.flushdb/0.
Returns the current health status without blocking.
See FerricStore.API.Generic.keys/1.
See FerricStore.API.System.multi/1.
See FerricStore.API.System.packed_batch_get/1.
See FerricStore.API.System.ping/0.
See FerricStore.API.System.pipeline/1.
See FerricStore.API.Generic.randomkey/0.
Returns true if FerricStore is ready to serve requests.
Gracefully shuts down FerricStore, flushing all pending data to disk.
Types
@type cas_opts() :: [{:ttl, non_neg_integer()}]
@type fetch_or_compute_opts() :: [ttl: pos_integer(), hint: binary()]
@type get_opts() :: [{:cache, atom()}]
@type key() :: binary()
@type set_opts() :: [ ttl: non_neg_integer(), exat: pos_integer(), pxat: pos_integer(), nx: boolean(), xx: boolean(), get: boolean(), keepttl: boolean(), cache: atom() ]
@type value() :: binary()
@type write_error() :: {:error, binary() | {:timeout, :unknown_outcome}}
@type zrange_opts() :: [{:withscores, boolean()}]
Functions
@spec await_ready(keyword()) :: :ok
Blocks until FerricStore is fully ready to serve requests.
Polls Health.check/0 until all shards are alive and all Raft leaders
are elected. Returns :ok when ready, raises on timeout.
Call this in your application's start/2 after FerricStore is in your
supervision tree, or in test setup, to ensure writes won't fail.
Options
:timeout- max milliseconds to wait (default: 30_000):interval- polling interval in ms (default: 100)
Examples
# In your Application.start/2:
def start(_type, _args) do
children = [
{FerricStore, []},
MyApp.Repo,
MyAppWeb.Endpoint
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
{:ok, pid} = Supervisor.start_link(children, opts)
FerricStore.await_ready()
{:ok, pid}
end
# With custom timeout:
FerricStore.await_ready(timeout: 60_000)
@spec batch_set([{binary(), binary()}]) :: [:ok | write_error()] | write_error()
See FerricStore.API.Generic.dbsize/0.
See FerricStore.API.System.echo/1.
See FerricStore.API.Flow.flow_approval_approve/2.
See FerricStore.API.Flow.flow_approval_get/2.
See FerricStore.API.Flow.flow_approval_list/1.
See FerricStore.API.Flow.flow_approval_reject/2.
See FerricStore.API.Flow.flow_approval_request/2.
See FerricStore.API.Flow.flow_attribute_values/3.
See FerricStore.API.Flow.flow_attributes/2.
See FerricStore.API.Flow.flow_budget_commit/4.
See FerricStore.API.Flow.flow_budget_get/2.
See FerricStore.API.Flow.flow_budget_list/1.
See FerricStore.API.Flow.flow_budget_release/3.
See FerricStore.API.Flow.flow_budget_reserve/3.
See FerricStore.API.Flow.flow_by_correlation/2.
See FerricStore.API.Flow.flow_by_parent/2.
See FerricStore.API.Flow.flow_by_root/2.
See FerricStore.API.Flow.flow_cancel/2.
See FerricStore.API.Flow.flow_cancel_many/3.
See FerricStore.API.Flow.flow_circuit_close/2.
See FerricStore.API.Flow.flow_circuit_get/2.
See FerricStore.API.Flow.flow_circuit_list/1.
See FerricStore.API.Flow.flow_circuit_open/2.
See FerricStore.API.Flow.flow_claim_due/2.
See FerricStore.API.Flow.flow_complete/3.
See FerricStore.API.Flow.flow_complete_many/3.
See FerricStore.API.Flow.flow_create/2.
See FerricStore.API.Flow.flow_create_many/3.
See FerricStore.API.Flow.flow_effect_compensate/3.
See FerricStore.API.Flow.flow_effect_confirm/3.
See FerricStore.API.Flow.flow_effect_fail/3.
See FerricStore.API.Flow.flow_effect_get/3.
See FerricStore.API.Flow.flow_effect_reserve/4.
See FerricStore.API.Flow.flow_extend_lease/3.
See FerricStore.API.Flow.flow_fail/3.
See FerricStore.API.Flow.flow_fail_many/3.
See FerricStore.API.Flow.flow_failures/2.
See FerricStore.API.Flow.flow_get/2.
See FerricStore.API.Flow.flow_governance_ledger/2.
See FerricStore.API.Flow.flow_governance_overview/1.
See FerricStore.API.Flow.flow_history/2.
See FerricStore.API.Flow.flow_info/2.
See FerricStore.API.Flow.flow_limit_get/2.
See FerricStore.API.Flow.flow_limit_lease/2.
See FerricStore.API.Flow.flow_limit_list/1.
See FerricStore.API.Flow.flow_limit_release/2.
See FerricStore.API.Flow.flow_limit_spend/2.
See FerricStore.API.Flow.flow_list/2.
See FerricStore.API.Flow.flow_policy_get/2.
See FerricStore.API.Flow.flow_policy_set/2.
See FerricStore.API.Flow.flow_reclaim/2.
See FerricStore.API.Flow.flow_retention_cleanup/1.
See FerricStore.API.Flow.flow_retry/3.
See FerricStore.API.Flow.flow_retry_many/3.
See FerricStore.API.Flow.flow_rewind/2.
See FerricStore.API.Flow.flow_run_steps_many/2.
See FerricStore.API.Flow.flow_schedule_create/2.
See FerricStore.API.Flow.flow_schedule_delete/2.
See FerricStore.API.Flow.flow_schedule_fire/2.
See FerricStore.API.Flow.flow_schedule_fire_due/1.
See FerricStore.API.Flow.flow_schedule_get/2.
See FerricStore.API.Flow.flow_schedule_list/1.
See FerricStore.API.Flow.flow_schedule_pause/2.
See FerricStore.API.Flow.flow_schedule_resume/2.
See FerricStore.API.Flow.flow_search/1.
See FerricStore.API.Flow.flow_signal/2.
See FerricStore.API.Flow.flow_spawn_children/3.
See FerricStore.API.Flow.flow_start_and_claim/4.
See FerricStore.API.Flow.flow_stats/2.
See FerricStore.API.Flow.flow_step_continue/5.
See FerricStore.API.Flow.flow_stuck/2.
See FerricStore.API.Flow.flow_terminals/2.
See FerricStore.API.Flow.flow_transition/4.
See FerricStore.API.Flow.flow_transition_many/5.
See FerricStore.API.Flow.flow_value_mget/2.
See FerricStore.API.Flow.flow_value_put/2.
@spec flushall() :: :ok | {:error, term()}
See FerricStore.API.System.flushall/0.
See FerricStore.API.Generic.flushdb/0.
@spec health() :: Ferricstore.Health.health_result()
Returns the current health status without blocking.
Examples
iex> FerricStore.health()
%{status: :ok, shard_count: 4, shards: [...], uptime_seconds: 120}
See FerricStore.API.Generic.keys/1.
See FerricStore.API.System.multi/1.
See FerricStore.API.System.packed_batch_get/1.
See FerricStore.API.System.ping/0.
See FerricStore.API.System.pipeline/1.
See FerricStore.API.Generic.randomkey/0.
@spec ready?() :: boolean()
Returns true if FerricStore is ready to serve requests.
Examples
iex> FerricStore.ready?()
true
@spec set(key(), value(), set_opts()) :: :ok | {:ok, value() | nil} | nil | write_error()
@spec shutdown() :: :ok
Gracefully shuts down FerricStore, flushing all pending data to disk.
Flushes Raft batchers, BitcaskWriters, shard pending writes, and triggers a WAL rollover. Call before stopping the application to ensure zero data loss.
Examples
FerricStore.shutdown()
Application.stop(:ferricstore)