ScopedCache
A wrapper class for accessing the cache.
Prefixes a string before each key to avoid conflicts.
Constructor Summary
Public Constructor | ||
public |
constructor(keyPrefix: string, version: number) Create a new ScopedCache object by passing in the key prefix descired |
Member Summary
Public Members | ||
public |
cache: * |
|
public |
prefix: * |
|
public |
version: * |
Private Members | ||
private |
|
Method Summary
Public Methods | ||
public |
generateScopedKey(inKey: string): string Generate a scoped key by adding our prefix to the incoming key |
|
public |
Get a cached object |
|
public |
Get a cached object from the global cache (skipping the scope prefix) |
|
public |
async initCache(): * Initialise the cache for this scope |
|
public |
Set a key in our cache |
|
public |
Set a key in our global cache, skipping the scoped prefix |
|
public |
A helper "wrap" function that will return a cached value if present |
|
public |
async wrapGlobal(key: string, fn: function, ttl: function | number): * A helper "wrap" function that will return a cached value if present (in the global scope) |
Private Methods | ||
private |
async _initCache(): * Internal cache initialisation |
Public Constructors
Public Members
public cache: * source
public prefix: * source
public version: * source
Private Members
private _initCachePromise: * source
Public Methods
public generateScopedKey(inKey: string): string source
Generate a scoped key by adding our prefix to the incoming key
Params:
Name | Type | Attribute | Description |
inKey | string |
public async get(key: string): Object | undefined source
Get a cached object
Params:
Name | Type | Attribute | Description |
key | string | Unique key name for this cache entry |
public async getGlobal(key: string): Object | undefined source
Get a cached object from the global cache (skipping the scope prefix)
Params:
Name | Type | Attribute | Description |
key | string | Unique key name for this cache entry |
public async set(key: string, value: Object, ttl: Function | number): * source
Set a key in our cache
Return:
* |
public async setGlobal(key: string, value: Object, ttl: Function | number): * source
Set a key in our global cache, skipping the scoped prefix
Return:
* |
public async wrap(key: string, fn: function, ttl: function | number): * source
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
Params:
Name | Type | Attribute | 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 |
|
How long the cache entry should last in milliseconds Can be a number or a function that will return a number |
Return:
* |
public async wrapGlobal(key: string, fn: function, ttl: function | number): * source
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
Params:
Name | Type | Attribute | 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 |
|
How long the cache entry should last in milliseconds Can be a number or a function that will return a number |
Return:
* |