Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

querymemcache

0.1.2 • Public • Published

querymemcache

querymemcache is a node.js module designed to allow you to cache the frequent queries to the DB with using of memcache. It can work with any SQL database.

Installation

Using npm:

$ npm install --save querymemcache

If you don't have or don't want to use npm:

$ cd ~/.node_modules
$ git clone git://github.com/bgrusnak/querymemcache.git

Usage

To require the library and initialize it

import QueryMemCache from 'querymemcache';
var cache=QueryMemCache({
  lifetime: 300, // cache lifetime in seconds
  servers: 'localhost:11211', // local server
    options: {
        maxKeySize: 2000  // the size of the key
    }
})
 

Methods

There only one method

process

Check and cache the results of queryFunction

.process({observe:observedFields, change:changedFields}, queryFunction, callbackFunction)

Parameters:

Name Description Type Required
observe List of field names or arrays [field, operand, value] which needs to be observed Array No
change List of field names or arrays [field, operand, value] which will b changed Array No
queryFunction The function, which will called if no valid data is available Function Yes
callbackFunction The function, which will receive the result of the cache process Function No

Requirements

  • node.js v7.10.0+ (7.10.0 is the version I used to develop this module. I'm unsure if it will work with previous ones. If you run a previous version, and it works, let me know and I'll update this)
  • memcached 2.2.2+

Contributions

If you run into problems, have questions, or whatever else you can open an issue on this repository. If you'd like to submit a patch, shoot me a pull request. I'd like to keep this module simple, so if you want to add all kinds of crazy functionality - you might want to fork. When in doubt, send a pull request - the worst that can happen is that I won't merge it.

License

MIT © Ilya Shlyakhovoy

Install

npm i querymemcache

DownloadsWeekly Downloads

2

Version

0.1.2

License

MIT

Last publish

Collaborators

  • avatar