2.1.2 • Published 7 years ago

hyperlru v2.1.2

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

hyperlru

Last version Build Status Coverage Status Dependency status Dev Dependencies Status NPM Status Donate

Tiny & Fast LRU Implementation as possible.

Features

  • Fast: High performance (See benchmark).
  • Simple: The whole project is ~60 lines of code.
  • Lightweight: The package weighs less than a megabyte, with zero dependencies.

There are a lot of LRU implementations, but most of them have a poor perfomance and they are hard to understand.

hyperlru is an Abstract LRU implementation using traditional and efficienty data structures:

  • Double Linked List: It maintains the least recent list of items.
  • Hash Table It keeps the data for easily access to cache content.

For use it, you need to provide one of the created providers:

Install

$ npm install hyperlru --save

Usage

const hyperlru = require('hyperlru')
const myProvider = require('my-hyperlru-provider')

const createLRU = hyperlru(myProvider)
const cache = createLRU({max: 1000})

Benchmark

namesizegzipsetget1updateget2evict
lru-fast2.34 kB793 B68552710521550251594003
tiny-lru4 kB1.64 kB41591074618909159254042
lru_cache2.19 kB756 B53201448910785159634242
simple-lru-cache1.43 kB565 B3289121348600152663334
hyperlru-object433 B265 B11528800620586351039
hashlru628 B332 B44385834470359603474
hyperlru-map329 B232 B850455540304397690
lru6.07 kB1.86 kB26723302314238981347
lru-cache19.1 kB6.23 kB989470230344536773
secondary-cache22.6 kB6.54 kB14272292274045791164
quick-lru1.23 kB489 B24412075252521192525
modern-lru2.27 kB907 B1019253120212456731
mkc10.5 kB3.61 kB72912307151129575

API

hyperlru(options)

options

max

Type: number Default: 1000

Max of element to keep into the cache.

.set(key, value)

Set the value of the key and mark the key as most recently used.

It returns the value.

.get(key)

Query the value of the key and mark the key as most recently used.

It returns the value of key if found; undefined otherwise.

.peek(key)

Query the value of the key without marking the key as most recently used.

It returns the value of key if found; undefined otherwise.

.keys()

It retrieves all the keys currently in the cache.

.values()

It retrieves all the values currently in the cache.

.clear()

Clear all the elements in the cache.

.remove(key)

Remove the value from the cache.

Returns: value of key if found; undefined otherwise.

License

MIT © Kiko Beats.

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago