Storage

interface Storage

Storage (in most cases persistent) that holds data items. Collection of items are organized in named StorageTables.

Concurrency and Multiple Instances

It is safe to use multiple Storage instances that reference the same underlying database concurrently, whether within the same process or across different processes (for example, a mobile application and an app extension sharing an App Group container).

Implementations provide concurrency guarantees through the underlying database engine:

  • Atomicity: Individual operations on StorageTable (such as insert, update, delete, and get) are atomic.

  • Contention Handling: When multiple connections or processes attempt to access or modify the database simultaneously, implementations configure appropriate lock wait mechanisms (e.g., SQLite's busy_timeout on mobile platforms, transaction queues in IndexedDB, or MVCC in relational databases). Operations will automatically wait for concurrent locks to be released rather than immediately failing with contention errors. If contention persists longer than the configured timeout, the operation will fail with an exception.

Inheritors

Functions

Link copied to clipboard
abstract suspend fun getTable(spec: StorageTableSpec): StorageTable

Get the table with specific name and features.

Link copied to clipboard
abstract suspend fun purgeExpired()

Reclaim the storage occupied by expired entries across all tables in this Storage object (even if these tables were never accessed using getTable in this session).