Skip to main content

Storage adapters

Strata Storage presents the same key/value operations to different storage backends. The selected adapter determines where values live and which platform can read them.

Adapter map​

AdapterWhere it runsWhat it storesSetup
MemoryJavaScript runtimeTemporary values, cleared on reloadIncluded in the default web set
LocalStorageBrowser pagePersistent values for one originIncluded in the default web set
SessionStorageBrowser pageValues for one tab sessionIncluded in the default web set
IndexedDBBrowser pagePersistent key/value dataIncluded in the default web set
CookiesBrowser pageSmall values in browser cookiesIncluded in the default web set
CacheBrowser pageJSON-serializable key/value data backed by the Cache APIIncluded in the default web set
URLBrowser pageSmall, shareable UI state in a query or hashRegister URLAdapter explicitly
PreferencesCapacitor iOS/AndroidNative app preferencesRegister Capacitor adapters
SecureCapacitor iOS/AndroidValues through Keychain or EncryptedSharedPreferencesRegister Capacitor adapters
SQLiteCapacitor iOS/AndroidNative SQLite-backed key/value dataRegister Capacitor adapters
FilesystemCapacitor iOS/AndroidOne JSON file per keyRegister Capacitor adapters

Browser quota, native storage limits and latency vary by browser, device, data size and operation. The table does not promise a capacity or benchmark. Test the read path on every platform you ship; device verification remains required for native adapters.

Choose an adapter​

defineStorage() registers the standard browser set and initializes on first operation. Without an explicit storage option, Strata tries the configured defaultStorages in order and uses the first available registered adapter. It does not rank adapters by speed, reliability or capacity.

import { defineStorage } from 'strata-storage';

const storage = defineStorage({
defaultStorages: ['indexedDB', 'localStorage', 'memory'],
});

await storage.set('draft', { title: 'Working copy' });
const draft = await storage.get<{ title: string }>('draft');

To target a specific adapter, supply its name. A fallback list is tried in your chosen order:

await storage.set('draft', { title: 'Working copy' }, { storage: 'indexedDB' });
await storage.set('session-note', 'editing', {
storage: ['sessionStorage', 'memory'],
});

Register native adapters before selecting preferences, secure, sqlite or filesystem:

import { defineStorage } from 'strata-storage';
import { registerCapacitorAdapters } from 'strata-storage/capacitor';

const nativeStorage = defineStorage();
await registerCapacitorAdapters(nativeStorage);
await nativeStorage.set('device-setting', 'on', { storage: 'preferences' });

The native example needs a Capacitor runtime and device verification. The Secure adapter uses platform facilities, but Strata's public options do not request biometric authentication or promise hardware-backed keys. Do not treat a browser test as proof of native behaviour.

Capability boundary​

The Strata API exposes key/value operations. Its IndexedDB and SQLite adapters use their underlying storage systems, but Strata does not expose native database transactions, indexes or raw SQL through storage. Use a platform API directly when you need those features. The Cache adapter stores serializable values, not Request/Response objects or service worker request caches; use the browser Cache API directly for those tasks.

storage.getCapabilities(name) reports an adapter's declared capabilities after it is registered. Capability flags describe the adapter interface; they do not replace a runtime availability check or a read/write/read test.

For custom adapter implementation and registration, follow the custom adapters guide. For optional Firebase adapters, follow the Firebase guide and select them explicitly after setup.