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.
Options (start_link/1)
:ttl— entry lifetime in ms (default 5 min).:sweep_interval— how often expired entries are actively purged, in ms (default 1 min).nil/0disables 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 aDowser.Client_mappingcall. Have it return the compiled schema rather than the raw mapping to keep cached values small.:eager— preload at startup viahandle_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
Returns a specification to start this module under a supervisor.
See Supervisor.
Clears the whole cache.
Returns the mapping for {config, index}, fetching lazily on a miss.
Invalidates a single {config, index} entry.