ExCellerate.Cache (excellerate v0.4.0)

Copy Markdown View Source

ETS-backed LRU cache for compiled expression functions.

Each entry stores {full_key, value, last_accessed, mod_name} where last_accessed is a monotonically increasing integer from :erlang.unique_integer([:monotonic]) and mod_name is the native BEAM module backing the entry (an atom) or nil for interpreted entries. The timestamp is updated on every get hit via :ets.update_element/3, so eviction always removes the least recently used entry.

The cache must be started as part of your application's supervision tree for caching to work. If it is not started, expressions will be parsed and compiled on every call.

Setup

Add ExCellerate.Cache to your supervision tree:

children = [
  ExCellerate.Cache,
  # ...
]

Supervisor.start_link(children, strategy: :one_for_one)