InMemoryStorage class

An in-memory ZenStorage implementation.

Useful for:

  • Testing: Inject as a mock without file I/O or platform dependencies.
  • Development: Fast iteration without worrying about stale persisted data.
  • Session caching: Persist data for the duration of an app session only.

Usage

// In tests:
final storage = InMemoryStorage();
ZenQueryCache.instance.setStorage(storage);

// In development builds:
await Zen.init(
  storage: kDebugMode ? InMemoryStorage() : SharedPreferencesStorage(),
);
Implemented types

Constructors

InMemoryStorage()

Properties

hashCode int
The hash code for this object.
no setterinherited
keys List<String>
Returns all keys currently in the store.
no setter
length int
Returns the number of entries in the store.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Removes all entries from the in-memory store.
containsKey(String key) bool
Returns true if the store contains an entry for key.
delete(String key) Future<void>
Delete data from storage.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(String key) Future<Map<String, dynamic>?>
Read data from storage.
override
toString() String
A string representation of this object.
inherited
write(String key, Map<String, dynamic> json) Future<void>
Write data to storage.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited