Cachios GET & Params example

node v6.17.1
version: 1.0.0
endpointsharetweet
This is an example of the caching capabilities of the Cachios wrapper.
const average = require('average'); const cachios = require('cachios'); const url = 'http://example.com/'; const requests = 1000; const maxRand = 3; 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, params: { token: Math.floor(Math.random() * maxRand), }, }).then(() => { // save our average time time = Date.now() - time; times.push(time); }); }); } console.log(`Queued ${requests} requests with a choice of ${maxRand} different parameters!`); // 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