CacheBase
Our base Cache implementation
Extend this class with new implementations to create different cache types (in-memory, database, file system etc.)
Constructor Summary
| Public Constructor | ||
| public |
constructor(options: Object) |
|
Member Summary
| Public Members | ||
| public |
failedCacheWraps: {} Create a stack containing all failed cache sessions |
|
| public |
memCache: {} |
|
| public |
Setting the memory options |
|
| public |
Create a stack and wait before every caching session is finished |
|
Method Summary
| Public Methods | ||
| public |
Get a cached object |
|
| public |
Get an array of all the cached keys matching the supplied prefix |
|
| public |
Set a key in our cache |
|
| public |
A helper "wrap" function that will return a cached value if present |
|
| Private Methods | ||
| private abstract |
Internal operation to delete a key |
|
| private abstract |
Internal implementation of Get() |
|
| private abstract |
Internal implementation of getKeys() |
|
| private abstract |
Internal implementation of Set() |
|
Public Constructors
public constructor(options: Object) source
Params:
| Name | Type | Attribute | Description |
| options | Object | ||
| options.useMemoryCache | boolean |
|
Use an in-memory layer on top of this cache Avoid hitting databases too often Not useful if using any distributed setup where memory will be out-of-sync between processes |
| options.memoryCacheTimeout | number | null |
|
Timeout for in-memory cache values Default is null, which will use the incoming ttl values for each key |
Public Members
public memCache: {} source
public pendingCacheWraps: {} source
Create a stack and wait before every caching session is finished
Public Methods
public async get(key: string, getFullObject: boolean): Object | undefined source
Get a cached object
public async getKeys(prefix: string): array<string> source
Get an array of all the cached keys matching the supplied prefix
Params:
| Name | Type | Attribute | Description |
| prefix | string |
|
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:
| * |
Private Methods
private abstract async _del(key: string) source
Internal operation to delete a key
Params:
| Name | Type | Attribute | Description |
| key | string | Key name to delete |
private abstract async _get(key: string): Object | undefined source
Internal implementation of Get()
Params:
| Name | Type | Attribute | Description |
| key | string | Unique key name for this cache entry |
