provide hierarchical read from different data resources, e.g, db, cache, file system...
// hierarchical read from memoryStore, fileStore
hier.chain([ memoryStore, fileStore ]).read('key').then(function(value){
// ...
})
every get/set value operations in this module, rely on this Store interface
so if you want to create your own Store class
, be sure to inherit fron Store
var hier= require('../');
var Store= hier.interface;
var util= require('util');
var Q= require('q');
var VirtualStore= function () {
var self= this;
self.stores= {};
Store.call(self);
}
util.inherits(VirtualStore, Store);
VirtualStore.prototype.get = function(key) {
var self= this;
return Q.delay(100).then(function () {
return self.stores[key] || null;
})
};
VirtualStore.prototype.set = function(key, value, opts) {
var self= this;
return Q.delay(100).then(function () {
self.stores[key]= value;
})
};
VirtualStore.prototype.destroy = function(key) {
delete self.stores[key];
};
hierarchical read from memoryStore
, fileStore
read key
in order from memoryStore
, fileStore
hier.chain([ memoryStore, fileStore ]).read('key')
.then(function (value) {
//...
})
MIT