storage/storage library
Zenify Storage Adapters
Zenify ships zero third-party dependencies. The ZenStorage interface is intentionally minimal so you can plug in any persistence backend.
Important: treat json as an opaque Map<String, dynamic>
Both ZenQueryCache ({data, timestamp, version}) and ZenMutationQueue
({queue, deadLetter} under key 'zen_mutation_queue') persist through
ZenStorage. Always serialize/deserialize the entire map (e.g. via
jsonEncode / jsonDecode) rather than assuming top-level keys.
Built-in (zero-dep) adapters
- InMemoryStorage — Stores data in-memory for the current session. Ideal for testing, CI, and debug builds.
Platform adapters (copy-paste recipes — zero extra package)
Zenify deliberately does NOT bundle shared_preferences, hive_ce,
drift, or flutter_secure_storage as dependencies. See
doc/offline_guide.md for full production recipes covering
SharedPreferencesAsync, Drift, Hive CE, and FlutterSecureStorage.
SharedPreferencesAsync
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:zenify/zenify.dart';
class SharedPreferencesStorage implements ZenStorage {
final String prefix;
final SharedPreferencesAsync _prefs;
SharedPreferencesStorage({
this.prefix = 'zen_query_',
SharedPreferencesAsync? prefs,
}) : _prefs = prefs ?? SharedPreferencesAsync();
@override
Future<void> write(String key, Map<String, dynamic> json) =>
_prefs.setString('$prefix$key', jsonEncode(json));
@override
Future<Map<String, dynamic>?> read(String key) async {
final raw = await _prefs.getString('$prefix$key');
if (raw == null) return null;
final decoded = jsonDecode(raw);
return decoded is Map<String, dynamic> ? decoded : null;
}
@override
Future<void> delete(String key) => _prefs.remove('$prefix$key');
}
See also example/lib/demos/06_offline_and_sync/storage.dart for a full production example.
Classes
- InMemoryStorage
- An in-memory ZenStorage implementation.
- ZenStorage
- Interface for persisting query data.