README
api-cache-mongoose
What is this?*
api-cache-mongoose is an NPM package to easily cache API calls to a MongoDB database and update them after X minutes.
Install
npm install --save api-cache-mongoose
Usage
You will need to set up a mongoose connection. Check examples/database.js
var mongoose = require('mongoose');
var ApiCache = require("api-cache-mongoose")( mongoose );
ApiCache only receives two parameters, The target URL (String) and minutes between api calls (Number) default=5
app.get("/users", function(req, res){
// ApiCache( url, minutes_between_call )
ApiCache("https://jsonplaceholder.typicode.com/users", 30).then(function(response){
// If the last call was less than 30 minutes ago response will load from the database
// Else response will be fetched from the api url
res.json(response);
}, function(err){
console.warn(err);
res.json({ success : false });
});
});
Additional Notes
- Please report any issues here