Skip to content

πŸ“¦ Storage

Ekrol34 edited this page Nov 25, 2025 · 1 revision

The Storage module provides a persistent key-value storage system built on top of the Json module. It allows storing and retrieving JSON objects, strings, and lists across sessions by saving data into files located in the ./Storage/ directory.

The system automatically manages file rotation with size limits, keeping an index file (index.json) to map keys to file identifiers. This ensures efficient storage even for large datasets.

Behaviour

The module revolves around the singleton class STORAGE.
It provides methods to insert, update, retrieve, and delete data. Internally, data is distributed across multiple JSON files, with an index file maintaining the mapping between keys and files.

The module supports strings, JSON objects, lists of strings, and lists of JSON objects.

Methods

SetJson

void SetJson(String name, Json data)

Stores a JSON object under the given key.

Parameters:

  • name: Key name.
  • data: JSON object to store.

SetString

void SetString(String name, String data)

Stores a string under the given key.

Parameters:

  • name: Key name.
  • data: String value to store.

SetStringList

void SetStringList(String name, List<String> data)

Stores a list of strings under the given key.

Parameters:

  • name: Key name.
  • data: List of strings to store.

SetJsonList

void SetJsonList(String name, List<Json> data)

Stores a list of JSON objects under the given key.

Parameters:

  • name: Key name.
  • data: List of JSON objects to store.

GetJson

Json GetJson(String name)

Retrieves a JSON object by key.

Parameters:

  • name: Key name.

Returns: The stored JSON object.

GetString

String GetString(String name)

Retrieves a string by key.

Parameters:

  • name: Key name.

Returns: The stored string.

GetStringList

List<String> GetStringList(String name)

Retrieves a list of strings by key.

Parameters:

  • name: Key name.

Returns: The stored list of strings.

GetJsonList

List<Json> GetJsonList(String name)

Retrieves a list of JSON objects by key.

Parameters:

  • name: Key name.

Returns: The stored list of JSON objects.

Delete

void Delete(String name)

Removes a value from storage.

Parameters:

  • name: Key name.

Notes: If the key does not exist, no action is taken.

Clear

void Clear()

Removes all stored data, deletes all associated JSON files, and resets the index file.

Clone this wiki locally