Docs Hex.pm

SuperCache

High-performance in-memory caching library for Elixir backed by partitioned ETS tables with experimental distributed cluster support. Transparent local and distributed modes, configurable consistency (async / sync / strong / Raft), batch operations, and multiple data structures.

Features

  • Partitioned ETS storage — splits data across N tables to reduce contention
  • Multiple data structures — tuples, key-value namespaces, queues, stacks, structs
  • Distributed clustering — node discovery, partition assignment, replication
  • Configurable consistency — async, sync (quorum), strong (WAL), opt-in Raft
  • Batch operations — put_batch!/1, add_batch/2, remove_batch/2
  • Performance optimized — compile-time log elimination, inlined routing, worker pools
  • Health monitoring — cluster health, replication lag, telemetry events

Installation

Requires Erlang/OTP 25+ and Elixir 1.15+.

def deps do
  [{:super_cache, "~> 1.2"}]
end

Quick Start

SuperCache.start!()

SuperCache.put!({:user, 1, "Alice"})
SuperCache.get!({:user, 1})
# => [{:user, 1, "Alice"}]

# Key-value namespace
alias SuperCache.KeyValue
KeyValue.add("session", :user_1, %{name: "Alice"})
KeyValue.get("session", :user_1)

See Usage Guide for the complete API reference and Distributed Guide for cluster setup.

Performance

OperationThroughput
put! (local)~1.2M ops/sec
get! (local)~2.1M ops/sec
KeyValue.add_batch (10k)~1.1M ops/sec

Distributed modes (3 nodes, µs per operation)

Lower is better. Raft figures use a real replicated group (2 or 3 voters).

ModeRFput!get! :primaryget! :quorum
:async223 µs0.76 µs78 µs
:sync2106 µs0.45 µs60 µs
:strong2106 µs0.46 µs57 µs
:raft21,111 µs5.63 µs72 µs
:async316 µs1.08 µs101 µs
:sync3102 µs0.47 µs79 µs
:strong3122 µs0.42 µs82 µs
:raft36,768 µs48.49 µs82 µs

Raft writes are fsync- and quorum-bound (~8–10× slower than strong with two voters, ~50× with three). Raft primary reads also pay a query barrier and, when the client is not the leader, an RPC round-trip. Quorum reads cost about the same in every mode. Write latency is roughly flat as cluster size grows once the voter count is fixed.

Distributed latency and cluster-size scaling (1 / 3 / 5 nodes) are recorded in benchmarks/results/distributed-scaling.md; the full Raft comparison and the multi-voter membership fix are documented in benchmarks/results/raft-comparison.md.

Guides

Examples

mix run examples/local_mode_example.exs
mix run examples/distributed_mode_example.exs

AI Agent Skills

Machine-readable skill files live under skills/. See that directory for installation into consuming apps.

License

MIT License. See LICENSE for details.