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 Translator will be created if:

  • There is no ‘metadata’ file, or

  • the original Translator is too old (see max_age), or

  • the 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 original Translator. For details, see ConfigMetadata.

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 Translator before it must be recreated. Pass zero to force recreation, or None to 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 Translator instance with a config_metadata attribute.

Raises:

ConfigurationChangedError – If the configuration has changed and on_config_mismatch='raise'.

See also

The from_config() method, which will read the config_path.