A GenServer that serializes locale data loading to prevent race conditions.
When multiple processes request the same locale concurrently,
the first request triggers the load and subsequent requests
wait for it to complete. This avoids duplicate loads and
redundant :persistent_term.put/2 calls (each of which
triggers a global GC).
The server is started as part of the Localize supervision
tree. All locale loading goes through load_and_store/2 which
delegates to this server.
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears the locale validation cache.
Loads and stores locale data, serialized through the GenServer.
Starts the loader GenServer.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear_locale_cache() :: :ok
Clears the locale validation cache.
This is called when the supported locales change to ensure stale resolutions are not returned.
@spec load_and_store(Localize.Locale.Provider.locale(), Keyword.t()) :: :ok | {:error, Exception.t()}
Loads and stores locale data, serialized through the GenServer.
If the locale is already loaded, returns :ok immediately
without contacting the server. Otherwise, delegates to the
GenServer which ensures only one load per locale occurs.
Arguments
localeis a locale identifier atom or aLocalize.LanguageTag.t/0.optionsis a keyword list of options.
Options
:provideris the module implementingLocalize.Locale.Providerto use. The default isLocalize.Locale.default_provider/0.
Returns
:okon success.{:error, exception}if the locale data could not be loaded.
Starts the loader GenServer.