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.
nedbfile/memory backed cache w/ simple garbage collection
npm install restify-nedb --save
var express = require'express';var app = express;var server = require'http'createServerapp;appset'port' 1337;appuseexpresscompress;appuseexpressmethodOverride;appuseexpressbodyParser;var restify = require'restify-nedb'mount;var config = require'restify-nedb'config;var path = require'path';// some sample middlware to throw at itvarconsole.log'here\'s a sample middleware...';return next;;// default config optionsvar opts =filePath: pathjoin__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.// accepts sync/blocking// cfg.makeDataStore();// api = new restify(cfg, app);// or async <3cfgmakeDataStoreif !errapi = ds_cfg app;;;serverlistenappget'port'console.log'restify-nedb example listening on %s' appget'port';;
|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 |
nedbinstance going, use this to create one -- otherwise pass it into your options object.
if (limit=20)then it will only return 20 objects, etc.
POST / PUT
_stalein your body/json will act as an override to
stale, say you need some things to last longer/shorter than other cached items
cake build:docswill build annotated source code documentation from docco
cake build:coffeewill compile coffee from
/srcto js in
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.