Abstract persistence component that stores data in flat files and caches them in memory.

Extends: MemoryPersistence

implements: IConfigurable


The FilePersistence class allows you to create persistence components that store data in flat files and chache them in memory.

Important points

  • 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 the self._items property and calling the save method.

Configuration parameters

  • path: path to the file where data is stored


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


Creates a new instance of the file persistence component.

public constructor(persister?: JsonFilePersister)

  • persister: JsonFilePersister - (optional) persister component that loads and saves data from/to a flat file.



JSON file persister.

protected _persister: JsonFilePersister

Instance methods


Configures the component by passing its configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.


class MyJsonFilePersistence extends FilePersistence<MyData> {
    public constructor(path?: string) {
        super(new JsonPersister(path));
    public async getByName(correlationId: string, name: string): Promise<MyData> {
        let item = this._items.find((d) => == name);
        retur item;
    public async set(correlatonId: string, item: MyData): Promise<MyData> {
        this._items = this._items.filter((d) => != name);
        return item;

See also