simple to use nedb cache layer with restful api routing
restify-nedb was built to give you restful api resources for client side application frameworks like
knockout.js as well as give you a simple file/memory based cache utilizing nedb. (ps, i love nedb, you should too.) If you haven't already checked it out, maybe you want to use it separate of all of this extra stuff, do it. It's like sqlite, with a subset of mongodb's api. Really neat.
nedbapi I need to wrap in, if you need the core crud stuff, this should work well for you
nedbfile/memory backed cache w/ simple garbage collection
npm install restify-nedb --save
app, so you can do that a number of ways,
/* example in .js */var express = require'express';var app = express;var restify = require'restify-nedb'mount;var config = require'restify-nedb'config;varconsole.log'here\'s a sample middleware...';return next;;// default config optionsvar opts =filePath: __dirname + '/db/filestore.db'maxAge: 1000 * 60 * 60prefix: '/session'middleware: sampleMiddleware;// initialize our config objectcfg = opts;// if you aren't already using an nedb// instance, then calling this will create// one for you.cfgmakeDataStore;// builds routesapi = cfg app;
express = require "express"app = module.exports = expressrestify = require"restify-nedb"mountconfig = require"restify-nedb"config=consolelog "here's a sample middleware..."nextopts =filePath: confapppathscachemaxAge: 1000 * 60 * 60prefix: "/session"middleware: sampleMiddlewarecfg = opts# if you aren't already using an nedb# instance, then calling this will create# one for you.cfgmakeDataStore# builds routesapi = cfgapp
|ds||DataStore||allow for outside nedb processes to be restified. tip: |
|prefix||String||defines the first route path, for instance |
|version||String||not preferred, as a rule i feel these aren't the best idea for your api, last thing you want is fragmentation in your api|
|exclude||Array||excludes keys/values from the api, good for things like |
|middleware||Array||middlewares, ie passport authentication, logging, analytics|
|memoryStore||Boolean||whether or not keep an in-memory store or a file based persistant store, defaults to |
|fileName||String||file name for your nedb filestore|
|filePath||String||bit easier to change the path and view the contents instead of digging through |
|maxAge||Number||if set to |
_stalein your body/json will act as an override to
stale, say you need some things to last longer/shorter than other cached items
mocha test\crud.coffee -R spec --compilers coffee:coffee-script
cake docs, this way if I forget, you can easily skim thru the source --
/docsshould be included.
The MIT License (MIT)Copyright (c) 2013 David HigginbothamPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.