fix(caching): properly respect ttl for all cache levels

This commit is contained in:
2021-05-10 14:26:32 +00:00
parent f7b6df5ff7
commit 6b57e8b1f3
7 changed files with 88 additions and 20 deletions

View File

@ -21,7 +21,23 @@ tap.test('should cache a value', async () => {
})
);
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
console.log(result);
expect(result.contents.toString()).to.equal('heythere');
});
tap.test('should respect ttl', async (tools) => {
await testLevelCache.storeCacheEntryByKey(
'mykey',
new CacheEntry({
contents: Buffer.from('heythere'),
ttl: 1000,
typeInfo: 'string',
})
);
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
expect(result.contents.toString()).to.equal('heythere');
await tools.delayFor(1100);
const result2 = await testLevelCache.retrieveCacheEntryByKey('mykey');
expect(result2).to.be.null;
});
tap.start();