$ cnpm install fs-memory-store

Filesystem store with in-memory cache
This was built for usage with eight-track, an HTTP fixture library. It is designed for ease-of-access while debugging. By default, items will be stored to separate .json files in the folder.
Install the module with: npm install fs-memory-store
// Generate a store inside of `http-fixtures`
var Store = require('fs-memory-store');
var store = new Store(__dirname + '/http-fixtures');
// Save a value
store.set('hello', {world: true}, function (err) {
// If there was an error, `err` will be it
// We have created `http-fixtures/hello.json`
/*
{
"world": true
}
*/
// Load the value
store.get('hello', function (err, val) {
// If there was an error, `err` will be it
// Log our value
console.log(val); /* {world: true} */
});
// Load an non-existent value
store.get('wat', function (err, val) {
// If there was an error, `err` will be it
// Log our value
console.log(val); /* null */
});
});
fs-memory-store returns Store as its module.exports.
Store(dir, options)Constructor for a new store
String, Directory to generate our store inside ofObject, Container for options/flags
String, Extension to save values under. By default, this is .jsonFunction, Stringifier to pass values through when saving to disk
JSON.stringify with an indenation of 2Function, Parser to pass values through when loading from disk
JSON.parseStore#get(key, cb)Retrieve an item from memory with a fallback to disk.
String, Identifier to retrieve item byFunction, Error-first callback function to receive item value
(err, val)Error|null, If there was an error, this will be itMixed|null, If the value was found, this will be it. If it was not found, this will be null.Store#set(key, val, cb)Save an item to memory and disk
String, Identifier to save item underMixed, Value to save under the keyFunction, Error-first callback function to handle errors
(err)Error|null, If there was an error, this will be itStore#delete(key, cb)Delete an item from memory and disk
String, Identifier to delete item underFunction, Error-first callback function to handle errors
(err)Error|null, If there was an error, this will be itIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via grunt and test via npm test.
Support this project and others by twolfson via gittip.
Copyright (c) 2014 Todd Wolfson
Licensed under the MIT license.
Copyright 2013 - present © cnpmjs.org | Home |