Dowser. OpenSearch. MappingCacher
(Dowser.OpenSearch v0.4.0)
View Source
Per-node cache of OpenSearch index mappings, read by
Dowser.OpenSearch.Codec.
The cache is dowser_client's Dowser.MappingCacher — see it for how
entries are keyed, fetched and expired, and for the start_link/1 options.
This module is OpenSearch's own instance of it: its own process and ETS
table, configured from the :dowser_opensearch application environment.
This package doesn't start it. An application that casts documents against
the cluster's mappings — the default mapping source — starts it in its own
supervision tree, with its options (see Dowser.MappingCacher):
children = [MyApp.Search, {Dowser.OpenSearch.MappingCacher, ttl: :timer.minutes(10)}]Asked without having been started, it reports {:not_started, cacher}, which
Dowser.OpenSearch.Codec turns into a Dowser.MappingError by default. An
application that only casts with :struct, or with mappings of its own
(config :dowser_opensearch, mapping: MyApp.Mappings), doesn't need it.
Mappings that are never fetched
A mapping given in the application environment answers for its index without any request at all — and so can never fail to be fetched:
config :dowser_opensearch,
mappings: %{
"posts" => %{
"properties" => %{"published_at" => %{"type" => "date", "format" => "strict_date_time"}}
}
}It wins over the cache. Use it for an index whose mapping is pinned, and in
test suites, where it makes casting behave as it does in production without
a cluster to ask (put/3 does the same through a running cacher).
Summary
Functions
A child spec starting this cacher under its own name; see
Dowser.MappingCacher for the options.
Clears the whole cache.
Like lookup/2, but nil on any failure; see Dowser.MappingCacher.fetch/4.
The mapping of index on repo_config's cluster — lookup/2 as the
Dowser.Mapping behaviour, which makes this cacher the default mapping
source.
Returns the mapping for {context, index}; see Dowser.MappingCacher.get/3.
Invalidates a single {context, index} entry.
The cache key for {context, index}; see Dowser.MappingCacher.key/2.
Returns the mapping for {context, index}, telling one that can't exist
from one that couldn't be fetched; see Dowser.MappingCacher.lookup/4.
Caches mapping for index directly; see Dowser.MappingCacher.put/4.
Starts this cacher; see Dowser.MappingCacher for the options.
Functions
@spec child_spec(keyword()) :: Supervisor.child_spec()
A child spec starting this cacher under its own name; see
Dowser.MappingCacher for the options.
@spec clear() :: :ok
Clears the whole cache.
@spec fetch(Dowser.Repo.t(), term()) :: map() | nil
Like lookup/2, but nil on any failure; see Dowser.MappingCacher.fetch/4.
The mapping of index on repo_config's cluster — lookup/2 as the
Dowser.Mapping behaviour, which makes this cacher the default mapping
source.
@spec get(Dowser.Repo.t(), term()) :: {:ok, term()} | {:error, term()}
Returns the mapping for {context, index}; see Dowser.MappingCacher.get/3.
@spec invalidate(Dowser.Repo.t(), term()) :: :ok
Invalidates a single {context, index} entry.
@spec key(Dowser.Repo.Config.t(), term()) :: Dowser.MappingCacher.key()
The cache key for {context, index}; see Dowser.MappingCacher.key/2.
@spec lookup(Dowser.Repo.t(), term()) :: {:ok, map() | nil} | {:error, term()}
Returns the mapping for {context, index}, telling one that can't exist
from one that couldn't be fetched; see Dowser.MappingCacher.lookup/4.
Caches mapping for index directly; see Dowser.MappingCacher.put/4.
@spec start_link(keyword()) :: GenServer.on_start()
Starts this cacher; see Dowser.MappingCacher for the options.