How to configure and use Browser Storage (Storage Hub)
1. Add the element
Place the **Storage Hub** element on the Bubble page where you want offline cache and exposed states.
2. Configure database and namespace
Set the element fields:
- **namespace** — groups cache keys (e.g. `dados_offline`)
- **idb_database_name** — IndexedDB database name (common default: `UBS_DB`)
- **idb_store_name_meta**, **idb_store_name_cache**, **idb_store_name_records** — object store names (defaults: `meta`, `cache`, `records`)
Keep these values consistent between the element and actions that read/write data.
3. Parameter prefix (API Connector)
Set **paramPrefix** to **`_p_`** or **`_api_c2_`** to match the connector/API you used for the return type. The plugin converts each cached item to that shape when publishing `return_dataset_N`.
4. Return slots (up to 15)
For each index 1–15 you can set:
- **return_dataset_key_N** — text: identifies the dataset in cache (logical key in IndexedDB)
- **return_dataset_type_N** — Bubble data type used in the UI (must match the **API Connector** type)
- **return_dataset_N** — exposed state: list of that type, after **paramPrefix** conversion
5. Initial cache bootstrap
Use the action that accepts a **datasets_kv** list (key + JSON string pairs):
- Known meta keys (e.g. `bootstrap_status`, `session_config`) go to the **meta** store
- Other keys become **cache** entries with the matching `dataset_key`
On success, the plugin can republish meta, cache summary, queue, and configured slots. Typical events: **bootstrap_completed**, **bootstrap_failed**.
6. Load a dataset on demand
Use **load dataset from cache** (or your plugin’s equivalent):
- Provide **dataset_key**, **namespace_override** if needed, **target_return_slot** (within your element’s limit), and whether to publish states
- The list for that slot always uses **API Connector** conversion with the element’s **paramPrefix** (or the action’s, if you pass one)
Useful event: **dataset_loaded**; on error: **error_occurred**.
7. Queue operations (offline → sync)
Create, update, and delete queued record actions:
- Update the **cache** array for the given `dataset_key`
- Write/update **records** with operation (`create`, `update`, `delete`) and payload
Use **get pending records** to publish count, JSON list, and aggregated **sync_payload_json**. Events: **records_loaded**, **sync_requested** (when there are pending items), **error_occurred**.
8. Clear cache
- Single dataset: removes that cache key and republishes states
- Full clear: optional inclusion of meta and/or queue (`records`)
Event: **cache_cleared** (when applicable).
9. Debug
Turn on **enable_debug_logs** on the element for browser console output during development.
10. Best practices
- Keep **paramPrefix** consistent with the API Connector type for each list
- Use the same **namespace** and store names in bootstrap, load, and clear
- In Repeat Groups: **Type of content** = API Connector type (`return_dataset_type_N`), **Data source** = Storage Hub’s **return_dataset_N**
Demo editor:
https://bubble.io/page?id=mentions-20237&tab=Design&name=storageLive demo:
https://mentions-20237.bubbleapps.io/version-test/storageDocumentation:
https://mentions-20237.bubbleapps.io/version-test/help_storage