id_translation.Translator.load_persistent_instance#
- classmethod Translator.load_persistent_instance(cache_dir, config_path, extra_fetchers=(), max_age='12h', on_config_changed='recreate')[source]#
Load or create a persistent
fetch_all-instance.Instances are created, stored and loaded as determined by a metadata file located in the given cache_dir. A new
Translatorwill be created if:There is no ‘metadata’ file, or
the original
Translatoris too old (see max_age), orthe current configuration – as defined by
(config_path, extra_fetchers, clazz)– has changed in such a way that it is no longer equivalent configuration used to create the originalTranslator. For details, seeConfigMetadata.
Warning
This method is not thread safe.
- Parameters:
cache_dir – Root directory where the cached translator and associated metadata is stored.
config_path – Path to the main TOML configuration file.
extra_fetchers – Paths to fetching configuration TOML files. If multiple fetchers are defined, they are ranked by input order. If a fetcher defined in the main configuration, it will be prioritized (rank=0).
max_age – The maximum age of the cached
Translatorbefore it must be recreated. Pass zero to force recreation, orNoneto ignore.on_config_changed – One of
raise|recreate. If'raise', crash instead of creating a new instance if the configuration (as determined by config_path and extra_fetchers) has changed.
- Returns:
A new or cached
Translatorinstance with aconfig_metadataattribute.- Raises:
ConfigurationChangedError – If the configuration has changed and
on_config_mismatch='raise'.
See also
The
from_config()method, which will read the config_path.