Class: LRU

LRU

new LRU(maxSize, getSizenullable, onRemovenullable)

An LRU cache, used for caching ChainBlocks.

Parameters:
Name Type Attributes Description
maxSize Number
getSize function <nullable>
onRemove function <nullable>
Source:

Methods

(private) _compact()

Compact the LRU linked list.

Source:

(private) _getSize(item) → {Number}

Calculate size of an item.

Parameters:
Name Type Description
item Object
Source:
Returns:

Size.

Type
Number

get(key) → {Object}

Retrieve an item from the cache.

Parameters:
Name Type Description
key String | Number
Source:
Returns:

Item.

Type
Object

has(key) → {Boolean}

Test whether the cache contains a key.

Parameters:
Name Type Description
key String | Number
Source:
Returns:
Type
Boolean

iterator() → {function}

Create an iterator with a next method.

Source:
Returns:
Type
function

keys() → {Array.<String>}

Collect all keys in the cache, sorted by LRU.

Source:
Returns:
Type
Array.<String>

remove(key) → {Boolean}

Remove an item from the cache.

Parameters:
Name Type Description
key String | Number
Source:
Returns:

Whether an item was removed.

Type
Boolean

reset()

Reset the cache. Clear all items.

Source:

set(key, value)

Add an item to the cache.

Parameters:
Name Type Description
key String | Number
value Object
Source:

toArray() → {Array.<Object>}

Convert the LRU cache to an array of items.

Source:
Returns:
Type
Array.<Object>