Socket
Socket
Sign inDemoInstall

lru-queue

Package Overview
Dependencies
9
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lru-queue

LRU Queue


Version published
Weekly downloads
4M
increased by2.2%
Maintainers
1
Install size
847 kB
Created
Weekly downloads
 

Readme

Source

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); // limit size to 3

Each queue exposes three methods:

queue.hit(id)

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)

queue.delete(id);

id's can be cleared from queue externally

queue.delete('raz'); // size: 2
queue.delete('cztery'); // size: 1
queue.clear();

Resets queue

queue.clear(); // size: 0

Tests Build Status

$ npm test

Keywords

FAQs

Last updated on 26 Apr 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc