import FileStore from "./FileStore" ; import StoreCache from "./StoreCache" ; import StoreLogger from "./StoreLogger" ; import IStore from "./IStore" ; export default class MessageStore { store : IStore ; cache : StoreCache ; logger : StoreLogger ; constructor ( directory ) { this . logger = new StoreLogger ( ) ; this . store = new FileStore ( directory , this . Logger ) ; this . cache = new StoreCache ( this . Logger ) ; } /**
     * A getter that returns an instance of logger
     * Purpose of this is to be able to extend this class
     * and use a different type of logger (that inherits from StoreLogger)
     */ get Logger ( ) { return this . logger ; } /**
     * A getter that returns an instance of store
     * Purpose of this is to be able to use a different type of store
     * that would implement the IStore interface
     */ get Store ( ) { return this . store ; } param id param message public save ( id , message ) { this . Store . save ( id , message ) ; this . cache . addOrUpdate ( id , message ) ; } param id returns public read ( id ) { var message = this . cache . getOrAdd ( id , ( ) => this . Store . read ( id ) ) ; return message ; } }