- Source:
Methods
get(key, seconds, fn) → {object}
Tries to get a value from cache, if the value does not exist it will run the function, try and store the output for the specified seconds and then return the value.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | the key by which the cached value is accessed |
seconds |
number | the length of time the cache tries to store the value for |
fn |
function | if no values has been cached it will run this function to create the value |
- Source:
Returns:
- Type
- object
get(key, fn) → {object}
Tries to get a value from cache, if the value does not exist it will run the function, try and store the output for as long as it can and then return the value.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | the key by which the cached value is accessed |
fn |
function | if no values has been cached it will run this function to create the value |
- Source:
Returns:
- Type
- object
get(key) → {object}
Gets a value from cache.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | the key by which the cached value is accessed |
- Source:
Returns:
- Type
- object
getPromise(key, seconds, fn) → {Promise.<object>}
Tries to get a value from cache as a resolved promise, if the value not exist it will run the function which must return a promise, then returns a promise. Once the generated promise has been resolved it caches the returned value (and try and store it for the specified number of seconds), and then resolves the returned promise with this value.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | the key by which the cached value is accessed |
seconds |
number | the length of time the cache tries to store the value for |
fn |
function | if no values has been cached it will run this function to create a promise |
- Source:
Returns:
- Type
- Promise.<object>
getPromise(key, fn) → {Promise.<object>}
Tries to get a value from cache as a resolved promise, if the value not exist it will run the function which must return a promise, then returns a promise. Once the generated promise has been resolved it caches the returned value (for as long as it can), and then resolves the returned promise with this value.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | the key by which the cached value is accessed |
fn |
function | if no values has been cached it will run this function to create a promise |
- Source:
Returns:
- Type
- Promise.<object>
info()
Provides info about the state of the cache; useful for debugging.
- Source:
put(key, value) → {object}
Puts a value into cache.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | the key by which the cached value is accessed |
value |
object | the value to be cached |
- Source:
Returns:
- Type
- object
remove(key)
Removes a value from cache.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | the key by which the cached value is accessed |
- Source:
removeAll()
Removes all values from cache i.e. resets it.
- Source: