Skip to content

shenfe/lru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lru

♻️ LRU (Least Recently Used) Cache.

  • single file ✨
  • browser✔
  • Node.js✔
  • dependencies
  • babel
  • polyfills

Installation

$ npm install --save llrruu

Usage

import

const LRU = require('llrruu');

create

The module exported is both a constructor and a factory function. It accepts either a number or an object.

const lru1 = new LRU(10);
const lru2 = LRU(10);
const lru3 = LRU({
    maxSize: 10,
    onEvict: (key, val) => console.log(`${key} is being kicked out, with its value `, val)
});

api

lru.set('a', 1);    // will affect the order
lru.get('a');       // will affect the order
lru.val('a', 1);
lru.val('a');
lru.remove('a');
lru.keys();
lru.size();
lru.clear();

Test

$ npm test

License

MIT

About

♻️ LRU (Least Recently Used) cache.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published