diff --git a/src/writr-cache.ts b/src/writr-cache.ts index 52b00d8..c53ab41 100644 --- a/src/writr-cache.ts +++ b/src/writr-cache.ts @@ -68,13 +68,14 @@ export class WritrCache { } public hash(markdown: string, options?: RenderOptions): string { - const key = JSON.stringify({markdown, options}); + const content = {markdown, options}; + const key = JSON.stringify(content); let result = this._hashStore.get(key); if (result) { return result; } - result = this._hashStore.hash(key); + result = this._hashStore.hash(content); this._hashStore.set(key, result); return result; diff --git a/test/writr.test.ts b/test/writr.test.ts index 02092b4..93db993 100644 --- a/test/writr.test.ts +++ b/test/writr.test.ts @@ -203,7 +203,8 @@ describe('writr', () => { const writr = new Writr('# Hello World'); // By defualt cache is enabled const result = await writr.render(); expect(result).toEqual('

Hello World

'); - expect(await writr.cache.get('0a210f5c18c7eceb1355ed9a5e23810c3f42a5379d7a0ab2e0d21b0b9051586f')).toEqual('

Hello World

'); + const hashKey = writr.cache.hashStore.hash({markdown: '# Hello World'}); + expect(await writr.cache.get(hashKey)).toEqual('

Hello World

'); const result2 = await writr.render(); expect(result2).toEqual('

Hello World

'); }); @@ -220,7 +221,8 @@ describe('writr', () => { const writr = new Writr('# Hello World'); // By defualt cache is enabled const result = writr.renderSync(); expect(result).toEqual('

Hello World

'); - expect(writr.cache.getSync('0a210f5c18c7eceb1355ed9a5e23810c3f42a5379d7a0ab2e0d21b0b9051586f')).toEqual('

Hello World

'); + const hashKey = writr.cache.hashStore.hash({markdown: '# Hello World'}); + expect(writr.cache.getSync(hashKey)).toEqual('

Hello World

'); const result2 = writr.renderSync(); expect(result2).toEqual('

Hello World

'); });