Class: LRU

utils.LRU

new LRU(capacity, getSizenullable)

An LRU cache, used for caching ChainEntrys.

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

Methods

(private) _appendList(item)

Append an item to the linked list (sets new tail).

Parameters:
Name Type Description
item LRUItem
Source:

(private) _compact()

Compact the LRU linked list.

Source:

(private) _getSize(item) → {Number}

Calculate size of an item.

Parameters:
Name Type Description
item LRUItem
Source:
Returns:

Size.

Type
Number

(private) _insertList(ref, item)

Insert item into the linked list.

Parameters:
Name Type Description
ref LRUItem | null
item LRUItem
Source:

(private) _prependList(item)

Prepend an item to the linked list (sets new head).

Parameters:
Name Type Description
item LRUItem
Source:

(private) _removeList(item)

Remove item from the linked list.

Parameters:
Name Type Description
item LRUItem
Source:

batch() → {LRUBatch}

Create an atomic batch for the lru (used for caching database writes).

Source:
Returns:
Type
LRUBatch

clear()

Clear the pending batch.

Source:

commit()

Commit the pending batch.

Source:

drop()

Drop the pending batch.

Source:

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

keys() → {Array:.<String:>}

Collect all keys in the cache, sorted by LRU.

Source:
Returns:
Type
Array:.<String:>

push(key, value)

Push an item onto the pending batch.

Parameters:
Name Type Description
key String
value Object
Source:

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:

start()

Start the pending batch.

Source:

toArray() → {Array:.<Object:>}

Convert the LRU cache to an array of items.

Source:
Returns:
Type
Array:.<Object:>

unpush(key)

Push a removal onto the pending batch.

Parameters:
Name Type Description
key String
Source:

values() → {Array:.<String:>}

Collect all values in the cache, sorted by LRU.

Source:
Returns:
Type
Array:.<String:>