lru-queue
Size limited queue based on LRU algorithm
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.
Installation
$ 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
Usage
Create queue, and provide a limit
var lruQueue = require('lru-queue');
var queue = lruQueue(3);
Each queue exposes three methods:
queue.hit(id)
Registers hit for given id (must be plain string).
queue.hit('raz');
If hit doesn't remove any old item from list it returns undefined
, otherwise it returns removed id.
queue.hit('dwa');
queue.hit('trzy');
queue.hit('raz');
queue.hit('dwa');
queue.hit('cztery');
queue.delete(id);
id's can be cleared from queue externally
queue.delete('raz');
queue.delete('cztery');
queue.clear();
Resets queue
queue.clear();
Tests
$ npm test