defmodule GitGud.Cache.L1 do
@moduledoc """
L1 level: per-node `ETS` cache. Sub-microsecond reads, in-process,
no network. Lives only in this BEAM.
"""
use Nebulex.Cache,
otp_app: :git_gud,
adapter: Nebulex.Adapters.Local
end
defmodule GitGud.Cache.L2 do
@moduledoc """
L2 level: `Nebulex.Adapters.Replicated` across clustered nodes.
Each clustered node holds a full copy; writes broadcast via `pg`.
Standalone deploys run as a single-member group with no network
traffic.
libcluster (configured in `runtime.exs`) connects peer nodes; the
Replicated adapter discovers siblings via `pg` once the cluster is
established.
"""
use Nebulex.Cache,
otp_app: :git_gud,
adapter: Nebulex.Adapters.Replicated
end
defmodule GitGud.Cache do
@moduledoc """
Application-wide in-memory cache backed by Nebulex.
Used for content that's expensive to compute and cheap to recompute
on a miss — currently:
* syntax-highlighted source blobs (`GitGud.SyntaxHighlight`)
* rendered markdown (`GitGud.Markdown`)
Both keys are derived from the *content hash*, not from any volatile
identifier, so cache entries are reusable across repos and branches
and never go stale: if the bytes change, the key changes.
## L1 / L2
Multilevel cache (`Nebulex.Adapters.Multilevel`) with two tiers:
* **L1 — `GitGud.Cache.L1`** — per-node ETS. Sub-microsecond reads.
* **L2 — `GitGud.Cache.L2`** — Replicated across cluster nodes.
Reads check L1 first; on miss they fall through to L2 and the
inclusive model promotes the hit back into L1 on the way out.
Writes fan out to both levels.
Standalone (single-node, no libcluster topology configured) deploys
work identically — L2 just runs as a single-member `pg` group.
"""
use Nebulex.Cache,
otp_app: :git_gud,
adapter: Nebulex.Adapters.Multilevel
end
1.8 KiB · text
5af55d9