mastermind.storage package

class mastermind.storage.persistent_cache.PersistentCacheManager[source]

Bases: object

Manages a persistent cache of Python objects on the file system.

The PersistentCacheManager class provides a simple interface for caching and retrieving data, using the pickle_io module for pickling to serialize and deserialize the objects.

The cache files are stored in the “data” directory, which is created automatically if it does not exist.

classmethod clear_all_cache() None[source]

Clears the entire cache by deleting all cache files.

classmethod set(key: str, value: Any) None[source]

Sets the cached value for the given key.

Parameters:
  • key (str) – The key associated with the cached value.

  • value (Any) – The value to be cached.

mastermind.storage.pickle_io.delete_pickled_data(filepath: str) None[source]

Delete a pickled file.

Parameters:

filepath (str) – The path to the file to delete.

mastermind.storage.pickle_io.ensure_parent_directory_exists(filepath: str) None[source]

Create the parent directory of a file if it doesn’t exist.

Parameters:

filepath (str) – The path to the file.

mastermind.storage.pickle_io.read_pickled_data(filepath: str) Any[source]

Read pickled data from a file and return it.

Parameters:

filepath (str) – The path to the file to read from.

Returns:

The pickled data being read, or None if the file does not exist.

Return type:

Any

mastermind.storage.pickle_io.write_pickled_data(filepath: str, data: dict) None[source]

Write pickled data to a file.

Parameters:
  • filepath (str) – The path to the file to write to.

  • data (dict) – The data to be pickled and written to the file.

class mastermind.storage.user_data.UserDataManager(data: dict, save_fn: Callable[[dict], None])[source]

Bases: object

Manages user data with a customizable data storage interface. You should not use this class directly. Use get_user_data_manager() instead.

This class wraps a data dictionary and provides methods to modify, retrieve, and clear user data, while ensuring that changes are saved through a provided save function.

clear_all() None[source]

Clears all the user data and saves the changes.

mastermind.storage.user_data.get_user_data_manager() UserDataManager[source]

Returns a new UserDataManager instance.