Candil.EnginePool (Candil v3.0.0)

Copy Markdown View Source

Lightweight LRU pool for Candil.Engine instances.

The pool keeps a list of engines ordered from most‑recently used to least‑recently used. Each engine is identified by its alias. The public API mimics a simple key‑value store with LRU semantics:

  • start_link/0 – starts the pool as a GenServer named __MODULE__.
  • put/1 – insert or update an engine, marking it as most recently used.
  • get/0 – return the least‑recently used engine and promote it to “most recently used”.
  • evict/0 – remove the least‑recently used engine from the pool and return it.

Summary

Types

Engine struct expected by the pool

Functions

Returns a specification to start this module under a supervisor.

Evicts the least recently used engine and returns it.

Returns the least recently used engine, promoting it to MRU.

Callback implementation for GenServer.init/1.

Marks an engine as most recently used (or inserts it).

Starts the engine pool GenServer.

Types

engine()

@type engine() :: struct()

Engine struct expected by the pool

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

evict()

@spec evict() :: engine() | :empty

Evicts the least recently used engine and returns it.

get()

@spec get() :: engine() | :empty

Returns the least recently used engine, promoting it to MRU.

init(opts)

Callback implementation for GenServer.init/1.

put(engine)

@spec put(engine()) :: :ok

Marks an engine as most recently used (or inserts it).

start_link(opts \\ [])

Starts the engine pool GenServer.