super-accessor
v1.0.0
Published
SuperAccessor is a middleware to make a easy way to fetch and set data in the db or cache
Downloads
2
Readme
SuperAccessor provide a easy way to fetch and set data in the database or cache . SuperAccessor accept four function as arguments.
Example
'use strict'
let SuperAccessor = require("super-accessor")
let Cache = require('../library/Cache')
let Database = require('../library/Database')
let hotNewsAccessor = new SuperAccessor(
function(id, callback){
Cache.get(id, function(err, result){
callback(err, JSON.parse(result))
})
},
function(id, obj, callback){
Cache.set(id, JSON.stringify(obj), function(err, result){
callback(null, result)
})
},
function(id, callback){
Database.get(id, function(err, result){
callback(err, JSON.parse(result))
})
},
function(id, obj, callback){
Database.set(id, JSON.stringify(obj), function(err, result){
callback(null, result)
})
});
// When you want to a list of hot news
// call hotNewsAccessor(id, function(err, result){
// })