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 key
String Key to get/set setFunction
function Function to set data if it is missing from the cache. setFunction should return a Promise ttl
Number | 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 key
String 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 keys
Array Array of keys to fetch ttl
Number | 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 key
String Key to set data for data
Object Data to store in cache ttl
Number | 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 data
Object Object of cachekey => data ttl
Number | 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 key
String Key to get/set setFunction
function Function to set data if it is missing from the cache. setFunction should return a Promise ttl
Number | function <optional>
How long cached result should last. Can be a number (seconds) or a function that will return a value