Constructor
new ReadBatcher(db)
- Description:
Create batcher instance
- Source:
Example
let batcher = new ReadBatcher(common.db);
let promise = batcher.getOne("events", {"_id":"5689b386909ee5c"});
Parameters:
| Name | Type | Description |
|---|---|---|
db |
Db | database object |
Methods
cache(collection, id, query, projection, data, multi)
- Description:
Cache data read from database
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
collection |
string | name of the collection where to update data |
id |
string | id of the cache |
query |
string | query for the document |
projection |
string | which fields to return |
data |
object | data from database |
multi |
boolean | true if multiple documents |
checkAll()
- Description:
Check all cache
- Source:
get(collection, query, projection, multi) → {Promise}
- Description:
Get data from cache or from db and cache it
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
collection |
string | name of the collection where to update data |
query |
object | query for the document |
projection |
object | which fields to return |
multi |
boolean | true if multiple documents |
Returns:
promise
- Type
- Promise
getData(collection, id, query, projection, multi) → {Promise}
- Description:
Get data from database
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
collection |
string | name of the collection for which to write data |
id |
string | id of cache |
query |
string | query for the document |
projection |
string | which fields to return |
multi |
boolean | true if multiple documents |
Returns:
promise
- Type
- Promise
getMany(collection, query, projection, callbackopt) → {Promise}
- Description:
Get multiple document from cache or from db and cache it
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
collection |
string | name of the collection where to update data |
|
query |
string | query for the document |
|
projection |
string | which fields to return |
|
callback |
function |
<optional> |
optional to get result, or else will return promise |
Returns:
if callback not passed, returns promise
- Type
- Promise
getOne(collection, query, projection, callbackopt) → {Promise}
- Description:
Get single document from cache or from db and cache it
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
collection |
string | name of the collection where to update data |
|
query |
string | query for the document |
|
projection |
string | which fields to return |
|
callback |
function |
<optional> |
optional to get result, or else will return promise |
Returns:
if callback not passed, returns promise
- Type
- Promise
invalidate(collection, query, projection, multi)
- Description:
Invalidate specific cache
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
collection |
string | name of the collection where to update data |
query |
object | query for the document |
projection |
object | which fields to return |
multi |
boolean | true if multiple documents |
keysFromProjectionObject(projection) → {object}
- Description:
Gets list of keys from projection object which are included
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
projection |
object | which fields to return |
Returns:
{keys - list of keys, have_projection - true if projection not empty}
- Type
- object
loadConfig()
- Description:
Reloads server configs
- Source:
schedule()
- Description:
Schedule next flush
- Source: