Dowser.Elasticsearch.MappingCacher (Dowser.Elasticsearch v0.1.0)

View Source

Per-node cache of Elasticsearch index mappings.

A GenServer owns an ETS table; reads go straight to ETS (concurrent, lock-free), and only misses/expired entries go through the GenServer — which de-duplicates concurrent fetches for the same key (single-flight).

Entries are keyed by {config endpoint, index}, so the same index on different configs is cached separately, and each fetch honours its config.

  • :ttl — entry lifetime in ms (default 5 min).
  • :sweep_interval — how often expired entries are actively purged, in ms (default 1 min). nil/0 disables active sweeping; lazy expiration on read still applies.
  • :fetch(config, index -> {:ok, value} | {:error, reason}), how a mapping is loaded on a miss. Defaults to a Dowser.Client _mapping call. Have it return the compiled schema rather than the raw mapping to keep cached values small.

  • :eager — preload at startup via handle_continue/2: false (default, lazy), a list of {config, index}, or a 0-arity fun returning one.

Whether the cacher is started at all (and with which options) is decided by the supervisor — see Dowser.Elasticsearch.Application.

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears the whole cache.

Returns the mapping for {config, index}, fetching lazily on a miss.

Invalidates a single {config, index} entry.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

Clears the whole cache.

get(config, index)

Returns the mapping for {config, index}, fetching lazily on a miss.

invalidate(config, index)

Invalidates a single {config, index} entry.

start_link(opts \\ [])