Creates a new instance of the persistence.
(optional) a loader to load items from external datasource.
(optional) a saver to save items to external datasource.
Clears component state.
(optional) transaction id to trace execution through call chain.
callback function that receives error or null no errors occured.
Closes component and frees used resources.
(optional) transaction id to trace execution through call chain.
callback function that receives error or null no errors occured.
Checks if the component is opened.
true if the component has been opened and false otherwise.
Opens the component.
(optional) transaction id to trace execution through call chain.
callback function that receives error or null no errors occured.
Saves items to external data source using configured saver component.
(optional) transaction id to trace execution through call chain.
(optional) callback function that receives error or null for success.
Sets references to dependent components.
references to locate the component dependencies.
Generated using TypeDoc
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.
References
*:logger:*:*:1.0
(optional) ILogger components to pass log messagesExample
class MyMemoryPersistence extends MemoryPersistence<MyData> { public getByName(correlationId: string, name: string, callback: (err, item) => void): void { let item = _.find(this._items, (d) => d.name == name); callback(null, item); }); public set(correlatonId: string, item: MyData, callback: (err) => void): void { this._items = _.filter(this._items, (d) => d.name != name); this._items.push(item); this.save(correlationId, callback); } } let persistence = new MyMemoryPersistence(); persistence.set("123", { name: "ABC" }, (err) => { persistence.getByName("123", "ABC", (err, item) => { console.log(item); // Result: { name: "ABC" } }); });