Class: caches.Cache

caches.caches.Cache(maxSize)

new caches.Cache(maxSize)

A very minimal cache. When the maximum size is reached, the oldest entry is removed from the cache.

Parameters:
Name Type Description
maxSize number

the maximum number of entries to keep.

Source:

Methods

contains(key) → {boolean}

Check if a key has already been added to the cache.

Parameters:
Name Type Description
key string

the key to check.

Source:
Returns:

true iif the key already exists, false otherwise.

Type
boolean

get(key) → {*|null}

Returns a single cache entry.

Parameters:
Name Type Description
key string

the key to get.

Source:
Returns:

the value associated with the given key.

Type
* | null

getOrDefault(key, defaultValue)

Returns a single cache entry or a default value if the cache key does not belong to the cache.

Parameters:
Name Type Description
key string

the key to get.

defaultValue * | null

the default value to return.

Source:

getOrPut(key, defaultValue) → {*|null}

Returns a single cache entry or add a new one if the cache key does not belong to the cache.

Parameters:
Name Type Description
key

the key to get.

defaultValue

the default to add to the cache.

Source:
Returns:
Type
* | null

invalidate()

Removes all cache entries.

Source:

put(key, value) → {*|null}

Adds a single cache entry.

Parameters:
Name Type Description
key string

the entry key.

value *

the entry value.

Source:
Returns:

the values previously associated with the given key.

Type
* | null

remove(key) → {*|null}

Removes a single cache entry.

Parameters:
Name Type Description
key string

the key to evict.

Source:
Returns:

the value previously associated with the given key.

Type
* | null

size() → {number}

Returns the number of cached objects.

Source:
Returns:

the number of cached objects.

Type
number