import IStoreWriter from './IStoreWriter' ; import IStoreReader from './IStoreReader' ; export default class StoreCache implements IStoreWriter , IStoreReader { cache : { [ key ] : string ; } ; writer : IStoreWriter ; reader : IStoreReader ; constructor ( _writer , _reader ) { this . cache = { } ; this . writer = _writer ; this . reader = _reader ; } public save ( id , message ) { this . writer . save ( id , message ) ; this . addOrUpdate ( id , message ) ; } public read ( id ) { if ( this . exists ( id ) ) { return this . cache [ id ] ; } var retValue = this . reader . read ( id ) ; if ( retValue !== undefined ) { this . addOrUpdate ( id , retValue ) ; } return retValue ; } private exists ? ( id ) { return this . cache . hasOwnProperty ( id ) ; } private addOrUpdate ( id , message ) { this . cache [ id ] = message ; } }