MemoryPersistence<T> class Null safety

Abstract persistence component that stores data in memory.

This is the most basic persistence component that is only able to store data items of any type. Specific CRUD operations over the data items must be implemented in child classes by accessing this.items property and calling save method.

The component supports loading and saving items from another data source. That allows to use it as a base class for file and other types of persistence components that cache all data in memory.


  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages


class MyMemoryPersistence extends MemoryPersistence<MyData> {

   Future<MyData> getByName(String? correlationId, String name) async {
        var item = items.firstWhere((d) => == name);
       return item;

    Future<MyData> set(String correlatonId, MyData item) async {
        items = items.where((d) => != name);
        await save(correlationId);
        return item;

var persistence = MyMemoryPersistence();

persistence.set("123", { name: "ABC" })
var item = await persistence.getByName("123", "ABC")
print(item);                   // Result: { name: "ABC" }
Implemented types


MemoryPersistence([ILoader<T>? loader, ISaver<T>? saver])
Creates a new instance of the persistence.


hashCode int
The hash code for this object.
items List<T>
read / write
loader ILoader<T>?
read / write
logger CompositeLogger
read / write
maxPageSize int
read / write
opened bool
read / write
runtimeType Type
A representation of the runtime type of the object.
saver ISaver<T>?
read / write


clear(String? correlationId) Future
Clears component state.
close(String? correlationId) Future
Closes component and frees used resources.
create(String? correlationId, T item) Future<T?>
Creates a data item.
deleteByFilterEx(String? correlationId, Function filter) Future
Deletes data items that match to a given filter.
getCountByFilterEx(String? correlationId, Function? filter) Future<int>
Gets a count of data items retrieved by a given filter.
getListByFilterEx(String? correlationId, Function? filter, Function? sort, dynamic select) Future<List<T>>
Gets a list of data items retrieved by a given filter and sorted according to sort parameters.
getOneRandom(String? correlationId, Function? filter) Future<T?>
Gets a random item from items that match to a given filter.
getPageByFilterEx(String? correlationId, Function? filter, PagingParams? paging, Function? sort, [dynamic select]) Future<DataPage<T>>
Gets a page of data items retrieved by a given filter and sorted according to sort parameters.
isOpen() bool
Checks if the component is opened.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
open(String? correlationId) Future
Opens the component.
save(String? correlationId) Future
Saves items to external data source using configured saver component.
setReferences(IReferences references) → void
Sets references to dependent components.
toString() String
A string representation of this object.


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