Skip to main content
Latest
class default
import { default } from "https://deno.land/x/lru_cache@6.0.0-deno.4/mod.ts";

Constructors

new
default(options?: Options<K, V>)
new
default(max: number)
new
default(options?: number | Options<K, V>)

Properties

private
[ALLOW_STALE]: any
private
[CACHE]: any
private
[DISPOSE]: any
private
[LENGTH_CALCULATOR]: (v: V, k: K) => number
private
[LENGTH]: any
private
[LRU_LIST]: Yallist<LEntry>
private
[MAX_AGE]: number
private
[MAX]: any
private
[NO_DISPOSE_ON_SET]: any
private
[UPDATE_AGE_ON_GET]: any
allowStale: boolean

Same as Options.allowStale.

readonly
itemCount

Return total quantity of objects currently in cache. Note, that stale (see options) items are returned as part of this item count.

readonly
length

Return total length of objects in cache taking into account length options function.

lengthCalculator: (value: V, key: K) => number

Resize the cache when the lengthCalculator changes. Same as Options.length.

max: number

Same as Options.max. Resizes the cache when the max changes.

maxAge: number

Same as Options.maxAge. Resizes the cache when the maxAge changes.

Methods

del(key: K): void

Deletes a key out of the cache.

dump(): Array<Entry<K, V>>

Return an array of the cache entries ready for serialization and usage with destinationCache.load(arr).

forEach<T = this>(callbackFn: (
this: T,
value: V,
key: K,
cache: this,
) => void
, thisArg?: T
): void

Just like Array.prototype.forEach. Iterates over all the keys in the cache, in order of recent-ness. (Ie, more recently used items are iterated over first.)

get(key: K): V | undefined

Will update the "recently used"-ness of the key. They do what you think. maxAge is optional and overrides the cache maxAge option if provided.

If the key is not found, will return undefined.

has(key: K): boolean

Check if a key is in the cache, without updating the recent-ness or deleting it for being stale.

keys(): K[]

Return an array of the keys in the cache.

load(arr: ReadonlyArray<Entry<K, V>>): void

Loads another cache entries array, obtained with sourceCache.dump(), into the cache. The destination cache is reset before loading new entries

peek(key: K): V | undefined

Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

(If you find yourself using this a lot, you might be using the wrong sort of data structure, but there are some use cases where it's handy.)

pop()
prune(): void

Manually iterates over the entire cache proactively pruning old entries.

reset(): void

Clear the cache entirely, throwing away all values.

rforEach<T = this>(callbackFn: (
this: T,
value: V,
key: K,
cache: this,
) => void
, thisArg?: T
): void

The same as cache.forEach(...) but items are iterated over in reverse order. (ie, less recently used items are iterated over first.)

set(
key: K,
value: V,
maxAge?: number,
): boolean

Will update the "recently used"-ness of the key. They do what you think. maxAge is optional and overrides the cache maxAge option if provided.

values(): V[]

Return an array of the values in the cache.