hoops_ai.storage.datastorage.memory_storage_handler

Classes

MemoryStorage()

class hoops_ai.storage.datastorage.memory_storage_handler.MemoryStorage

Bases: DataStorage

close()

Clears the stored data and metadata from memory.

Return type:

None

compress_store()

This method is a placeholder, as in-memory storage does not require compression.

Returns:

Always returns 0 as no compression is performed.

Return type:

int

format()

Returns the format of this storage.

Returns:

A string specifying that this is in-memory storage.

Return type:

str

get_file_path(data_key)

Since this is an in-memory storage, file paths do not exist. For compatibility with code that expects a directory path for the root (“”), we return a temporary directory path. For specific keys, we return a descriptive message.

Parameters:

data_key (str) – The data key.

Returns:

A temporary directory path for root key, or descriptive message for specific keys.

Return type:

str

get_group_for_array(array_name)

Determines which group an array belongs to based on the schema.

Parameters:

array_name (str) – Name of the array

Returns:

Group name for the array, or None if not found in schema

Return type:

str

get_keys()

Retrieves a list of all stored data keys.

Returns:

A list of keys in the storage.

Return type:

list

get_schema()

Retrieves the schema definition for this storage instance.

Returns:

The schema definition, or empty dict if no schema is set

Return type:

dict

load_data(data_key)

Loads data from memory by key.

Parameters:

data_key (str) – The key of the data to load.

Returns:

The loaded data.

Return type:

Any

Raises:

KeyError – If the key does not exist.

load_metadata(key)

Loads metadata by key from memory storage. Supports nested keys using ‘/’ as a separator.

Parameters:

key (str) – The metadata key, which can be a nested key using ‘/’ as a separator.

Returns:

The loaded metadata value.

Return type:

Any

Raises:

KeyError – If the key does not exist.

save_data(data_key, data)

Stores the data in memory and tracks file size.

Parameters:
  • data_key (str) – The key under which to store the data.

  • data (Any) – The data to store.

Return type:

None

save_metadata(key, value)

Stores metadata as a key-value pair in memory. Supports nested keys using ‘/’ as a separator.

Parameters:
  • key (str) – The metadata key, which can be a nested key using ‘/’ as a separator.

  • value (Any) – The metadata value.

Return type:

None

set_schema(schema)

Sets a schema definition for this storage instance. The schema defines how arrays should be organized into groups for merging.

Parameters:

schema (dict) – Schema definition containing group and array specifications

Return type:

None

validate_data_against_schema(data_key, data)

Validates data against the stored schema if present.

Parameters:
  • data_key (str) – The key under which the data will be stored

  • data (Any) – The data to validate

Returns:

True if valid or no schema present, False if validation fails

Return type:

bool