Created
July 15, 2020 12:49
-
-
Save slavahatnuke/8bdfc38335c9ea6e55b5bb3ac1ffaa27 to your computer and use it in GitHub Desktop.
Revisions
-
slavahatnuke created this gist
Jul 15, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ const LRU = require("lru-cache"); async function test1() { console.log('TEST1') const cache = new LRU({ max: 1, dispose: function (key, n) { console.log('close', key, n) }, maxAge: 1e3 }); cache.set('connection-1', 'CONNECTION_VALUE_1') cache.set('connection-1', 'CONNECTION_VALUE_2') cache.set('connection-2', 'CONNECTION_VALUE_2') } async function test2() { console.log('TEST2') const maxAge = 1e3; const cache = new LRU({ max: 100, dispose: function (key, n) { console.log('close', key, n) }, maxAge: maxAge, length: (n, key) => { // console.log('LEN', n, key) setTimeout(() => cache.get(key), maxAge + 1) return 1; } }); cache.set('connection-1', 'CONNECTION_VALUE_1') // console.log('GET-1', cache.get('connection-1')) // await new Promise((resolve) => { // setTimeout(resolve, 2e3) // }) // console.log('GET-2', cache.get('connection-1')) // cache.set('connection-1', 'CONNECTION_VALUE_2') } async function test() { await test1() await test2() } test().catch(console.error)