Strata Storage Examples
This directory contains practical examples demonstrating how to use Strata Storage in various scenarios.
advanced
1 item
Queue consented analytics events
Keep a bounded local analytics outbox with Strata Storage and send it to your own validated endpoint.
Angular storage service
Wrap the supported Strata Storage API in an Angular service for local drafts and subscriptions.
basic
1 item
Basic Usage Examples
Simple examples to get started with Strata Storage.
Cache management examples
A cache is useful only when a miss can be recovered. These examples cache JSON data in a browser adapter and let TTL remove stale entries. Strata's Cache adapter stores JSON-serializable key/value data; it is not the browser's Request/Response cache.
Capacitor App Examples
A Capacitor app can use the same set() and get() calls on web, iOS and Android after it registers the native adapters. A browser build exercises the web adapters; native persistence needs device testing.
Compression Examples
Strata's bundled LZ codec runs when the instance has compression.enabled true option on an unconfigured instance does not initialize the compressor.
Configuration Examples
Use defineStorage() for a web-ready instance. It registers the standard web adapters and initializes on the first operation.
Cross-tab change examples
Strata can notify another browser tab about a change to a supported shared adapter. A notification helps a view refresh; it does not make two concurrent writes atomic or synchronize an authenticated session.
Sync a local outbox
Queue browser writes with Strata Storage and replay them to an idempotent server endpoint.
Encryption Examples
Strata uses Web Crypto for encrypted values. Create an instance with encryption enabled, then provide a password at the operation or instance level. A plain defineStorage() instance does not initialize the encryption manager, even if a later set() passes encrypt: true.
Handle storage errors
Handle failed Strata Storage writes and reads using the public error classes and explicit fallback behavior.
Firebase Sync Examples
Copy-pasteable examples for syncing Strata Storage through Firebase (Cloud
Persist a form draft
Save, restore and discard a small form draft with Strata Storage without promising an upload or submission.
frameworks
3 items
Ionic Capacitor example
Prepare one Strata Storage instance for an Ionic app and register native adapters before the first operation.
Migration Examples
Examples of implementing data migrations in Strata Storage.
Multi-Storage Examples
A Strata instance can select from its registered adapters. The default list chooses the first available adapter at initialization; a later write error is not automatically retried elsewhere.
Offline support examples
Strata can keep a local draft while the network is unavailable. Sending that draft to a server is an application protocol: the server must accept an idempotency key and return a successful HTTP status before the client removes its queued write.
Measure storage work
Measure Strata Storage reads, writes and local query costs without invented benchmarks or unsupported indexes.
Query stored values
Query decoded Strata Storage values with supported operators and result options.
React Hooks Examples
Examples of using Strata Storage with React hooks integration.
React Native support
Strata Storage 3.1.4 does not register React Native storage adapters. The native adapters exported from strata-storage/capacitor use Capacitor plugins and require a Capacitor runtime. A React Native app cannot use them by selecting secure, sqlite or preferences in defaultStorages.
Local shopping cart
Keep a small browser cart with Strata Storage while leaving prices and checkout to the server.
Expire local values
Use Strata Storage TTL, absolute expiry and expiry inspection without treating client expiry as server authentication.
User Authentication Example
Strata Storage holds client-side key-value data. It does not authenticate a user, issue a session, or enforce server authorization. The host application must do those jobs. For a browser app, keep the session credential in a server-issued HttpOnly cookie; JavaScript and Strata's cookie adapter cannot create one.
Vue storage composable
Keep a small Vue value in browser storage and clean up the Strata Storage subscription on unmount.
Web Application Examples
These examples use Strata Storage for client-side key-value state. The server still owns authentication, payments and shared records.