new Cache( [options])
Create Cache object
This object will handle caching data for later use
Parameters:
| Name | Type | Argument | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Properties
|
Members
-
Prefix
-
Get the prefix used for this caching instance
Methods
-
<static> DB()
-
Return the sqlite3 database handle
Returns:
- Type
- Promise
-
<static> WrapGlobal(key, setFunction [, ttl])
-
Wrap a get request and pass a setter to tidy up the usual get/set boilerplate. This version sits in the global scope, rather than per-park.
Parameters:
Name Type Argument Description keyString Key to get/set setFunctionfunction Function to set data if it is missing from the cache. setFunction should return a Promise ttlNumber | function <optional>
How long cached result should last. Can be a number (seconds) or a function that will return a value -
Get(key)
-
Get a cached value
Parameters:
Name Type Description keyString Key to request associated data for Returns:
Returns Promise with data (or null if not cached)- Type
- Promise.<Object>
-
GetBulk(keys [, ttl])
-
Bulk get cache data
Parameters:
Name Type Argument Description keysArray Array of keys to fetch ttlNumber | function <optional>
How long this data should last in the cache (seconds). Calculated once for bulk query -
Set(key, data [, ttl])
-
Set a cached value
Parameters:
Name Type Argument Description keyString Key to set data for dataObject Data to store in cache ttlNumber | function <optional>
Time this data should be cached for (in seconds) Returns:
Returns Promise resolving if cached data was successfully set- Type
- Promise
-
SetBulk(data [, ttl])
-
Bulk set cache data
Parameters:
Name Type Argument Description dataObject Object of cachekey => data ttlNumber | function <optional>
How long this data should last in the cache (seconds). Calculated once for bulk query -
Wrap(key, setFunction [, ttl])
-
Wrap a get request and pass a setter to tidy up the usual get/set boilerplate
Parameters:
Name Type Argument Description keyString Key to get/set setFunctionfunction Function to set data if it is missing from the cache. setFunction should return a Promise ttlNumber | function <optional>
How long cached result should last. Can be a number (seconds) or a function that will return a value