Constructor
new ScopedCache(keyPrefix, versionopt, cacheObjectopt)
- Description:
- Create a new ScopedCache object by passing in the key prefix descired
- Source:
Parameters:
Name |
Type |
Attributes |
Default |
Description |
keyPrefix |
string
|
|
|
|
version |
number
|
<optional>
|
0
|
Cache version, bump this to invalidate existing cache entries for a scope |
cacheObject |
object
|
<optional>
|
null
|
Manually supply a cache object to use |
Classes
- ScopedCache
Methods
(async) _initCache()
- Description:
- Internal cache initialisation
- Source:
(async) blockOnPendingTransactions() → {Promise}
- Description:
- Block if we have any pending transactions
- Source:
Returns:
-
Type
-
Promise
generateScopedKey(inKey) → {string}
- Description:
- Generate a scoped key by adding our prefix to the incoming key
- Source:
Parameters:
Name |
Type |
Description |
inKey |
string
|
|
Returns:
Scoped key
-
Type
-
string
(async) get(key, getFullObjectopt, forceopt) → {Object|undefined}
- Description:
- Source:
Parameters:
Name |
Type |
Attributes |
Default |
Description |
key |
string
|
|
|
Unique key name for this cache entry |
getFullObject |
boolean
|
<optional>
|
false
|
Get the full cache entry, including expiry time, even if expired |
force |
boolean
|
<optional>
|
false
|
Force set, bypassing transaction blocks |
Returns:
Returns the object in the cache, or undefined if not present
-
Type
-
Object
|
undefined
(async) getGlobal(key, getFullObjectopt, forceopt) → {Object|undefined}
- Description:
- Get a cached object from the global cache (skipping the scope prefix)
- Source:
Parameters:
Name |
Type |
Attributes |
Default |
Description |
key |
string
|
|
|
Unique key name for this cache entry |
getFullObject |
boolean
|
<optional>
|
false
|
Get the full cache entry, including expiry time, even if expired |
force |
boolean
|
<optional>
|
false
|
Force set, bypassing transaction blocks |
Returns:
Returns the object in the cache, or undefined if not present
-
Type
-
Object
|
undefined
(async) getKeys(prefixopt) → {array.<string>}
- Description:
- Get an array of all the cached keys matching the supplied prefix
- Source:
Parameters:
Name |
Type |
Attributes |
Default |
Description |
prefix |
string
|
<optional>
|
''
|
|
Returns:
-
Type
-
array.<string>
(async) initCache()
- Description:
- Initialise the cache for this scope
- Source:
(async) runTransaction(func) → {promise}
- Description:
- Run a series of functions in a single transaction
- Source:
Parameters:
Name |
Type |
Description |
func |
functions
|
|
Returns:
-
Type
-
promise
(async) set(key, value, ttlopt)
- Description:
- Source:
Parameters:
Name |
Type |
Attributes |
Default |
Description |
key |
string
|
|
|
Unique key name for this cache entry |
value |
Object
|
|
|
|
ttl |
function
|
number
|
<optional>
|
3600000
|
How long the cache entry should last in milliseconds
Can be a number or a function that will return a number
Default 1 hour |
(async) setGlobal(key, value, ttlopt)
- Description:
- Set a key in our global cache, skipping the scoped prefix
- Source:
Parameters:
Name |
Type |
Attributes |
Default |
Description |
key |
string
|
|
|
Unique key name for this cache entry |
value |
Object
|
|
|
|
ttl |
function
|
number
|
<optional>
|
3600000
|
How long the cache entry should last in milliseconds
Can be a number or a function that will return a number
Default 1 hour |
(async) wrap(key, fn, ttlopt)
- Description:
- A helper "wrap" function that will return a cached value if present
This will call the supplied function to fetch it if the value isn't present in the cache
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
key |
string
|
|
Unique key name for this cache entry |
fn |
function
|
|
Fetch function that will be called if the cache entry is not present |
ttl |
function
|
number
|
<optional>
|
How long the cache entry should last in milliseconds
Can be a number or a function that will return a number |
(async) wrapGlobal(key, fn, ttlopt)
- Description:
- A helper "wrap" function that will return a cached value if present (in the global scope)
This will call the supplied function to fetch it if the value isn't present in the cache
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
key |
string
|
|
Unique key name for this cache entry |
fn |
function
|
|
Fetch function that will be called if the cache entry is not present |
ttl |
function
|
number
|
<optional>
|
How long the cache entry should last in milliseconds
Can be a number or a function that will return a number |