Cachios with custom cache strategy

node v6.17.1
version: 1.0.0
endpointsharetweet
const average = require('average'); const cachios = require('cachios'); const LRU = require('lru-cache'); cachios.cache = LRU(500); const url = 'http://example.com/'; const requests = 1000; let promise = Promise.resolve(); const times = []; // queue up a thousand synchronous requests for (let i = 0; i < requests; i += 1) { let time; promise = promise.then(() => { time = Date.now(); return cachios.get(url, { ttl: 1000, }).then(() => { // save our average time time = Date.now() - time; times.push(time); }); }); } console.log(`Queued ${requests} requests!`); // print our average once we finish :) promise.then(() => { console.log(`Request average: ${average(times)}ms across ${times.length} requests`); });
Loading…

no comments

    sign in to comment