ReadBatcher

ReadBatcher

Class for caching read from database

Constructor

new ReadBatcher(db)

Source:

Create batcher instance

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)

Source:

Cache data read from database

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 bool

true if multiple documents

checkAll()

Source:

Check all cache

get(collection, query, projection, multi) → {Promise}

Source:

Get data from cache or from db and cache it

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 bool

true if multiple documents

Returns:

promise

Type
Promise

getData(collection, id, query, projection, multi) → {Promise}

Source:

Get data from database

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 bool

true if multiple documents

Returns:

promise

Type
Promise

getMany(collection, query, projection, callbackopt) → {Promise}

Source:

Get multiple document from cache or from db and cache it

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}

Source:

Get single document from cache or from db and cache it

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)

Source:

Invalidate specific cache

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 bool

true if multiple documents

keysFromProjectionObject(projection) → {object}

Source:

Gets list of keys from projection object which are included

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()

Source:

Reloads server configs

schedule()

Source:

Schedule next flush