sensordb2 e64a8defe5 3.17 | há 1 ano atrás | |
---|---|---|
.. | ||
test | há 1 ano atrás | |
.lint | há 1 ano atrás | |
.npmignore | há 1 ano atrás | |
.travis.yml | há 1 ano atrás | |
CHANGES | há 1 ano atrás | |
LICENCE | há 1 ano atrás | |
README.md | há 1 ano atrás | |
index.js | há 1 ano atrás | |
package.json | há 1 ano atrás |
Originally derived from memoizee package.
It's low-level utility meant to be used internally within cache algorithms. It backs up max
functionality in memoizee project.
$ npm install lru-queue
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack
Create queue, and provide a limit
var lruQueue = require('lru-queue');
var queue = lruQueue(3); // limit size to 3
Each queue exposes three methods:
Registers hit for given id (must be plain string).
queue.hit('raz'); // size: 1
If hit doesn't remove any old item from list it returns undefined
, otherwise it returns removed id.
queue.hit('dwa'); // undefined, size: 2
queue.hit('trzy'); // undefined, size: 3 (at max)
queue.hit('raz'); // undefined, size: 3 (at max)
queue.hit('dwa'); // undefined, size: 3 (at max)
queue.hit('cztery'); // 'trzy', size: 3 (at max)
id's can be cleared from queue externally
queue.delete('raz'); // size: 2
queue.delete('cztery'); // size: 1
Resets queue
queue.clear(); // size: 0
$ npm test