Skip to content

Commit

Permalink
fixing reference
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray committed Oct 9, 2024
1 parent e2ef32e commit 5909000
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/writr-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(key);
if (result) {
return result;
}

result = this._hashStore.hash(key);
result = this._hashStore.hash(content);
this._hashStore.set(key, result);

return result;
Expand Down
6 changes: 4 additions & 2 deletions test/writr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<h1 id="hello-world">Hello World</h1>');
expect(await writr.cache.get('0a210f5c18c7eceb1355ed9a5e23810c3f42a5379d7a0ab2e0d21b0b9051586f')).toEqual('<h1 id="hello-world">Hello World</h1>');
const hashKey = writr.cache.hashStore.hash({markdown: '# Hello World'});
expect(await writr.cache.get(hashKey)).toEqual('<h1 id="hello-world">Hello World</h1>');
const result2 = await writr.render();
expect(result2).toEqual('<h1 id="hello-world">Hello World</h1>');
});
Expand All @@ -220,7 +221,8 @@ describe('writr', () => {
const writr = new Writr('# Hello World'); // By defualt cache is enabled
const result = writr.renderSync();
expect(result).toEqual('<h1 id="hello-world">Hello World</h1>');
expect(writr.cache.getSync('0a210f5c18c7eceb1355ed9a5e23810c3f42a5379d7a0ab2e0d21b0b9051586f')).toEqual('<h1 id="hello-world">Hello World</h1>');
const hashKey = writr.cache.hashStore.hash({markdown: '# Hello World'});
expect(writr.cache.getSync(hashKey)).toEqual('<h1 id="hello-world">Hello World</h1>');
const result2 = writr.renderSync();
expect(result2).toEqual('<h1 id="hello-world">Hello World</h1>');
});
Expand Down

0 comments on commit 5909000

Please sign in to comment.