1.0.4 • Published 6 years ago

api-cache-mongoose v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

api-cache-mongoose

NPM GitHub issues

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
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago