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. |
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. |
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. |
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. |
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. |
Returns:
- Type
- * | null
invalidate()
Removes all cache entries.
put(key, value) → {*|null}
Adds a single cache entry.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | the entry key. |
value |
* | the entry value. |
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. |
Returns:
the value previously associated with the given key.
- Type
- * | null
size() → {number}
Returns the number of cached objects.
Returns:
the number of cached objects.
- Type
- number