0.1.2 • Published 7 years ago

querymemcache v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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:

NameDescriptionTypeRequired
observeList of field names or arrays field, operand, value which needs to be observedArrayNo
changeList of field names or arrays field, operand, value which will b changedArrayNo
queryFunctionThe function, which will called if no valid data is availableFunctionYes
callbackFunctionThe function, which will receive the result of the cache processFunctionNo

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