View Source Fuzler (Fuzler v0.1.0)

A lightweight, reusable cache built on an ETS table, wrapped in a GenServer.

highlights

Highlights

  • Named ETS – give any atom as :table.
  • Public reads / protected writes:public, read_concurrency: & write_concurrency: enabled; only the owner process mutates the table.
  • O(1) table lookup – mapping from server‐name → table stored in :persistent_term, avoiding a GenServer.call/2 round‑trip for every public API invocation.
  • Hot reload, insert, get, predicate stream – as before.
  • Fuzzy full‑text search on keystext_search/3 uses String.jaro_distance/2 (or any custom scorer) and thresholding.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Fetches value for key, or nil if not present.

Inserts a {key, value} tuple into the cache.

Reloads the cache by wiping the table and invoking the loader again.

Starts the cache.

Returns a lazy stream of {key, value} pairs whose value satisfies predicate.(value). When no predicate given, returns every entry.

Top‐N fuzzy search selecting the scorer based on table size

Link to this section Types

@type key() :: term()
@opaque t()
@type value() :: term()

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

get(key, server \\ __MODULE__)

View Source
@spec get(key(), GenServer.server()) :: value() | nil

Fetches value for key, or nil if not present.

Link to this function

insert(tuple, server \\ __MODULE__)

View Source
@spec insert(
  {key(), value()},
  GenServer.server()
) :: :ok

Inserts a {key, value} tuple into the cache.

Link to this function

nif_similarity_score(q, t)

View Source
@spec nif_similarity_score(String.t(), String.t()) :: float()
Link to this function

reload(server \\ __MODULE__)

View Source
@spec reload(GenServer.server()) :: :ok

Reloads the cache by wiping the table and invoking the loader again.

@spec start_link(keyword()) :: GenServer.on_start()

Starts the cache.

Options:

  • :tablerequired atom, the ETS table name.
  • :loaderrequired () -> Enumerable.t() that yields {key, value}.
  • :ets_opts – extra ETS options merged with sensible defaults [:named_table, :public, read_concurrency: true, write_concurrency: true].
  • :name – process name (defaults to the module itself).
Link to this function

stream(predicate \\ fn _ -> true end, server \\ __MODULE__)

View Source
@spec stream((value() -> as_boolean(term())) | nil, GenServer.server()) ::
  Enumerable.t()

Returns a lazy stream of {key, value} pairs whose value satisfies predicate.(value). When no predicate given, returns every entry.

Link to this function

text_search(query, opts \\ [], server \\ __MODULE__)

View Source
@spec text_search(String.t(), keyword(), GenServer.server()) :: [
  {key(), value(), float()}
]

Top‐N fuzzy search selecting the scorer based on table size:

Returns a list of {key, value, score} sorted by descending similarity.