LRU

LRU

A Simple LRU Map
This maintains 2 maps internally and swaps them when one becomes full
NOTE: At any time size of the map will be from 0 to 2 * maxItems

Constructor

new LRU(optionsopt)

Source:
Example
const lru = new LRU({maxItems: 1000});
lru.set('hello', 'world');
lru.get('hello');
lru.delete('hello');
Parameters:
Name Type Attributes Default Description
options object <optional>
{}
Properties
Name Type Attributes Description
maxItems number <optional>

max items in the lru map

Members

size

Source:

returns the size of the lru map (number of items in the map)

Methods

clear()

Source:

removes all values from the lru map

delete(key) → {boolean}

Source:

deletes a value from the lru map

Parameters:
Name Type Description
key any
Returns:

whether any key was deleted

Type
boolean

get(key) → {any}

Source:

gets a value from the lru map

Parameters:
Name Type Description
key any
Returns:
Type
any

has(key) → {boolean}

Source:

returns whether a value exists in the lru map

Parameters:
Name Type Description
key any
Returns:
Type
boolean

(generator) keys()

Source:

return an iterator over the keys of the lru map

peek(key) → {any}

Source:

gets a value from the lru map without touching the lru sequence

Parameters:
Name Type Description
key any
Returns:
Type
any

set(key, value)

Source:

sets a value in the lru map

Parameters:
Name Type Description
key any
value any

totalSize() → {number}

Source:

Total size (including old + new) of the LRU cache

Returns:
Type
number

(generator) values()

Source:

return an iterator over the values of the lru map