1.0.7 • Published 6 years ago

cachemon v1.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Modules

Classes

Constants

Functions

Cachemon

exports.initialize ⇒ Promise.<any>

Kind: global constant of Cachemon

Param
config

exports.resource ⇒ CacheMonClient

Kind: global constant of Cachemon

Param
clientConfig

Example

const cnrCache = new CacheMonClient({
        name: 'DATA',
        executeCronJob: false,
        cronPeriod: '0 * * * * *',
        cronExecutorFn: (done) => {
            i++;
            console.log('Running');
            request({
                url: 'https://api.github.com/users/rajatady/repos?per_page=10',
                headers: {
                    'User-Agent': 'request'
                }
            }, (err, response, body) => {
                if (err) {
                    done();
                } else {
                    cnrCache.updateResourcePool(body)
                        .then(res => {
                            console.log('Done');
                        })
                        .catch(err => {
                            console.log(err);
                        })
                }
            });
        },
        requestMethod: 'GET',
        urlDomain: '/data'
    });


 cnrCache.on('updated', (data) => {
        console.log('Updated');
    });

 export default resource(cnrCache);

exports.hasKey ⇒ ⏏

Kind: global constant of Cachemon
Returns: Promise

ParamType
url
cacheModelCacheMonClient

exports.cacheMiddleware ⇒ function

Kind: global constant of Cachemon

ParamType
cacheModelCacheMonClient

exports.getResource ⇒ *

Kind: global constant of Cachemon

Param
resourceName

generateHash(str) ⇒ * | PromiseLike.<ArrayBuffer>

Kind: global method of Cachemon

Param
str

CacheMonClient ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new CacheMonClient(options)

ParamTypeDefaultDescription
optionsObjectThe options for the Cachemon Client
options.nameStringThe name of the client for which resources have to be scoped
options.allowFilteringStringWhether the domain should allow data filtering (Planned)
options.urlDomainStringThe url domain registered with express. To be used for advanced caching (Planned)
options.requestMethodStringGETThe HTTP request method for the url domain (Planned)
options.cronPeriodStringThe cron period in a standard glob format. Refer to https://www.npmjs.com/package/node-cron for more
options.purgeCronPeriodStringThe cron period for the purge function in a standard glob format. Refer to https://www.npmjs.com/package/node-cron for more
options.executeCronJobBooleanShould the cron function be executed
options.cronExecutorFnfunctionThe function to be executed whenever the cron job runs
options.updaterFnfunctionThe function to be executed whenever request is served from cache
options.purgeFnfunctionThe function to be executed whenever cron time for purge is reached
options.shouldRunUpdaterBooleanfalseShould the updater function run
options.shouldRunPurgeBooleanfalseShould the purge function run
options.maintainUrlsBooleanfalseShould a new data pool be created based on request url
options.preSendCallbackfunctionThe function which gets the control once the data from cache is evaluated and is ready to be sent

setData(key, value) ⇒ Promise.<any>

Set some data in the resource. The key will be prefixed with the resource name specified earlier

Kind: global function

ParamTypeDescription
keyStringThe key to be put in the cache
valueStringThe data to be saved

getData(key) ⇒ Promise.<any>

Get some data from the resource. The key will be prefixed with the resource name specified earlier

Kind: global function

ParamTypeDescription
keyStringThe key to fetch from the cache

setResourcePool(resourcePoolData) ⇒ Promise.<any>

Sets the data in the resource pool

Kind: global function

ParamTypeDescription
resourcePoolDataStringSet the data in the resource pool

getResourcePool() ⇒ Promise.<any>

Get the data from the resource pool

Kind: global function

appendToResourcePool(appendData) ⇒ Promise.<any>

Kind: global function

Param
appendData

updateResourcePool(updateData, preventEmit) ⇒ Promise.<any>

Kind: global function

ParamType
updateData
preventEmitBoolean

runCronJob()

Kind: global function

saveMeta(key, value) ⇒ Promise.<any>

Set the meta info in the cache

Kind: global function

Param
key
value

getMeta() ⇒ Promise.<any>

Get the meta info saved in the cache

Kind: global function

invalidateResourcePool() ⇒ Promise.<any>

Kind: global function

runUdaterFunction()

Manually run the updater function

Kind: global function

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago