import { IDecoration } from './util/color-util' ; import { TextDocument } from 'vscode' ; class CacheManager { private _dirtyCache : Map < string , Map < number , IDecoration [ ] > > ; private _decorationsCache : Map < string , Map < number , IDecoration [ ] > > ; constructor ( ) { this . _dirtyCache = new Map ( ) ; this . _decorationsCache = new Map ( ) ; } param { TextEditor } editor returns { ( Map < number , IDecoration [ ] > | null ) } public getCachedDecorations ( document ) { if ( ! document . isDirty && this . _decorationsCache . has ( document . fileName ) ) { return this . _decorationsCache . get ( document . fileName ) ; } if ( this . _dirtyCache . has ( document . fileName ) ) { return this . _dirtyCache . get ( document . fileName ) ; } return null ; } param { TextDocument } document param { Map < number , IDecoration [ ] > } deco public saveDecorations ( document , deco ) { document . isDirty ? this . _saveDirtyDecoration ( document . fileName , deco ) : this . _saveSavedDecorations ( document . fileName , deco ) ; } private _saveDirtyDecoration ( fileName , decorations ) { return this . _dirtyCache . set ( fileName , decorations ) ; } private _saveSavedDecorations ( fileName , decorations ) { return this . _decorationsCache . set ( fileName , decorations ) ; } public clearCache ( ) { this . _dirtyCache . clear ( ) ; this . _decorationsCache . clear ( ) ; } } const instance = new CacheManager ( ) ; export default instance ;