import FileStore from "./FileStore" ; import StoreCache from "./StoreCache" ; import StoreLogger from "./StoreLogger" ; export default class MessageStore { filestore : FileStore ; cache : StoreCache ; logger : StoreLogger ; constructor ( directory ) { this . logger = new StoreLogger ( ) ; this . filestore = new FileStore ( directory , this . logger ) ; this . cache = new StoreCache ( this . logger ) ; } param id param message public async save ( id , message ) { await this . filestore . save ( id , message ) ; this . cache . addOrUpdate ( id , message ) ; } param id returns public read ( id ) { if ( ! this . cache . exists ( id ) ) { var message = this . filestore . read ( id ) ; this . cache . getOrAdd ( id , message ) ; } return this . cache . getOrAdd ( id ) ; } }